其他分享
首页 > 其他分享> > UCF Local Programming Contest 2017 2020.4.7

UCF Local Programming Contest 2017 2020.4.7

作者:互联网

A Electric Bill

To encourage customers to conserve energy (and protect the environment), the electric companies typically have a lower rate for the first 1000 kilowatt-hour (KWH) of electric usage and a higher rate for the additional usage (KWH is a derived unit of energy equal to 3.6 megajoules).

The Problem:

Given the rate (per KWH) for the first 1000 KWH usage, the rate (per KWH) for the additional usage, and a customer’s energy consumption, you are to determine the charges (bill) for the customer.

The Input:

The first input line contains two integers (each between 2 and 20, inclusive), indicating the rate/KWH for the first 1000 KWH and the rate/KWH for the additional usage, respectively. The next input line contains a positive integer, n, indicating the number of customers to process. Each of the following n input lines contains an integer (between 1 and 50000, inclusive), indicating a customer’s energy consumption.

The Output:

For each customer, print the energy consumption, followed by a space, followed by the charges.

样例输入

6 10
4
1000 
1001 
700 
4800 

样例输出

1000 6000 
1001 6010 
700 4200 
4800 44000 
题解:签到题,输入一个n,如果没有超过1000,费用就是n*a,超过1000的话就把超过的乘上b(1000*a+(n-1000)*b)就好了
#include<iostream>
using namespace std;
int main(){
    int a,b,n,sum=0;
    int x[1001];
    cin>>a>>b;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x[i];
        if(x[i]<=1000){
        sum=x[i]*a;    
        }
        else{
            sum=1000*a+(x[i]-1000)*b;
        }
        cout<<x[i]<<" "<<sum<<endl;
    }
    return 0;
} 

B.Simplified Keyboard

Consider a simplified keyboard consisting of the 26 lowercase letters as illustrated below: 

企业微信截图_1585970612743.png

We define the neighbors of a key (letter) as all the letters adjacent to it.  For example, the neighbors of ‘a’ are {b, k, j}, neighbors of ‘b’ are {a, c, l, k, j}, neighbors of ‘n’ are {d, e, f, o, x, w, v, m}, and neighbors of ‘z’ are {p, q, r, y}. 

The Problem:   

Given two words consisting of lowercase letters only, you are to determine which of the following three cases applies to them:   

1. identical: this is when the two words are of the same length and they match letter-byletter.  For example, “cool” and “cool” are identical, “cool” and “col” are not, and “cool” and “colo” are not.   

2. similar: this is when the two words are of the same length, they are not identical words, and each corresponding two letters either match or are neighbors.  For example, “aaaaa” and “abkja” are similar, “moon” and “done” are similar, “knq” and “bxz” are similar, but “ab” and “cb” are not (because of ‘a’ in the first word and the corresponding ‘c’ in the second word).   

3. different: this is when neither of the above two cases applies to the two words, i.e., they are not identical and they are not similar.  For example, “ab” and “abc” are different, “ab” and “az” are different, and “az” and “za” are different. 

The Input:   

The first input line contains a positive integer, n, indicating the number of test cases to process.  Each of the following n input lines represents a test case, consisting of two words separated by one space.  Each word consists of lowercase letters only and will be between 1 and 20 letters, inclusive.

The Output:   

For each test case, output one line.  That line should contain the digit (number) 1, 2, or 3, to indicate which of the above three cases applies to the two input words. 

样例输入

7
a k
a a
a z
cool cool
aaaaa abkja
ab abc
az za

样例输出

2
1
3
1
2
3
3
题解:每个英文的八个方向都跟这个单词相似 比如a跟bkl相似,给你2个字符串,如果这两个字符串完全相等输出1,如果是相似的输出2,如果长度不同或
不相似也不相等输出3。用map做,利用map<char,string> mp['a']="bkl"把26的英文写出来,先一个循环判断是否相等或者不相等,如果不相等再来一
个循环进行判断有没有相似的英文。写得比较麻烦- -。
#include<iostream>
#include<map>
using namespace std;
int main(){
    map<char,string>mp;
    mp['a']="bkj";
    mp['b']="clkja";
    mp['c']="dmlkb";
    mp['d']="enmlc";
    mp['e']="fonmd";
    mp['f']="gpone";
    mp['g']="hqpof";
    mp['h']="irqpg";
    mp['i']="rqh";
    mp['j']="abkts";
    mp['k']="abclutsj";
    mp['l']="bcdmvutk";
    mp['m']="cdenwvul";
    mp['n']="defoxwvm";
    mp['o']="efgpyxwn";
    mp['p']="fghqzyxo";
    mp['q']="ghirzyp";
    mp['r']="hizq";
    mp['s']="jkt";
    mp['t']="jklus";
    mp['u']="klmvt";
    mp['v']="lmnwu";
    mp['w']="mnoxv";
    mp['x']="nopyw";
    mp['y']="opqzx";
    mp['z']="pqry";
    int t,flag,flag1;
    string a,b;
    cin>>t;
    while(t--){
        flag=0,flag1=0;
        cin>>a>>b;
        if(a.size()!=b.size()){
            cout<<"3"<<endl;
            continue;
        }
        for(int i=0;i<a.size();i++){
            if(a[i]!=b[i]){
                flag=1;
                break;
            }
        }
        if(flag==0){
            cout<<"1"<<endl;
            continue;
        }
        else{
            for(int i=0;i<a.size();i++){
                flag1=0;
                if(a[i]==b[i]){
                    flag1=1;
                    continue;
                }
                if(a[i]!=b[i]){
                    for(int j=0;j<mp[a[i]].size();j++){
                        if(mp[a[i]][j]==b[i]){
                            flag1=1;
                            break;
                        }
                    }
                }
                if(flag1==0){
                    break;
                }
            }
            if(flag1==1){
                cout<<"2"<<endl;
            }
            else{
                cout<<"3"<<endl; 
            }    
        }
    }
    return 0;
}
 C Singin' in the Rain

During the time of the 2016 UCF Local Programming Contest, Arup's younger daughter Anya (3 years old at the time), made Arup incessantly listen to Taylor Swift's song "Wildest Dreams".  A full year later, we are proud to report that Anya's listening habits have matured greatly.  Rather than wanting to hear the same song over and over again, Anya has embraced an embryonic notion of diversity in music.  Now, she wants to hear various different tracks, in sequence, all from the same CD.     

This year, it turns out that Anya's favorite CD is "Singing in the Rain", which her older sister Simran obtained when she performed in the "Singing in the Rain" production at a local theater. Whenever Anya is in the car with Arup, she'll listen to a track and then call out the number of the next track that she wants to listen to.  The problem is that Arup's car has a rather primitive CD player:    

• If track number k has completed, then track k+1 will play.  If track k is the last track on the CD, the CD will wrap around and track 1 will play.    

• Arup can also change tracks by pressing a forward button.  If track number k has completed, if Arup presses the forward button, then track k+2 will play.  If k is the last track and Arup presses forward when k finishes, the CD will wrap around and track 2 will play next.  If k is next to the last track and Arup presses forward when k finishes, track 1 will play next.    

• Arup can also change tracks by pressing a backward button.  If track number k has completed, if Arup presses the backward button, track number k will play again.  If k is the first track and Arup presses the backward button twice right after track 1 completes, the CD will wrap around and track t will play next, where t is the number of tracks on the CD.    

This means Arup is pressing either the forward or backward button a great deal.  Help him minimize the number of times he presses the buttons.     

The Problem:    

Given the number of tracks on Anya's favorite CD and the sequence of tracks Anya wants to be played, determine the minimum number of button presses Arup must make to get the appropriate sequence of songs played.  For the purposes of this problem, assume that at the very beginning the CD player is cued up to play the first song in the sequence (the first song Anya wants to be played), so Arup does not have to press any buttons for the first song in the sequence to be played, i.e., the first time any buttons might have to be pressed is in between the first and second songs in the sequence (after the first song in the sequence plays). 

The Input:   

The first input line contains a positive integer, n, indicating the number of test cases to process.  Each test case starts with two space separated integers on a single line: t (1 ≤ t ≤ 10^9), the number of tracks on Anya's favorite CD and s (1 ≤ s ≤ 1000), the number of songs Anya would like to listen to from the CD.  The second line of each test case contains s space separated integers, representing the sequence of tracks from the CD that Anya would like to listen to.  Each of these will be in between 1 and t, inclusive.   

The Output:   

For each test case, output a single integer on a line by itself indicating the minimum number of button presses Arup can use to play the desired sequence of songs from the CD.   

样例输入

3
68 6
67 57 66 67 48 15
1000000000 7
1 500000002 3 500000004 5 500000006 7
3 3
3 1 1

样例输出

73
3000000000
1
题解:要求的是把每首歌放完最少需要按几下按钮,你的初始位置在第一首歌,放完后你可以选择向前放(就是重新播放当前的歌),或者向后放(就是从第一首到第三首),

所以只需用两个函数分别计算从当前歌跳至下一首目标歌曲时,往前跳和往后跳所需次数,取min记录,最后求和即是答案
#include<iostream>
using namespace std;
int main(){
    int t;
    int n,k;
    long long a,b;
    long long sum;
    cin>>t;
    while(t--){
        sum=0;
        cin>>n>>k;
        cin>>a;
        for(int i=1;i<k;i++){
            cin>>b;
            if(a==b){
                sum=sum+1;
            }
            else if(a<b){
                sum=sum+min(b-a-1,n+a-b+1);
            }
            else{
                sum=sum+min(a-b+1,n+b-a-1);
            }
            a=b;
        }
        cout<<sum<<endl;
    }
    return 0;
} 

 

 



 

 

标签:Arup,Contest,2020.4,Programming,number,CD,track,mp,first
来源: https://www.cnblogs.com/liyongqi/p/12653399.html