量子团队的算法训练(20190523)

    xiaoxiao2022-07-12  160

    量子团队的算法训练(20190523)

    1.A - As Easy As A+B These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fairly difficulty to do such a thing. Of course, I got it after many waking nights. Give you some integers, your task is to sort these number ascending (升序). You should know how easy the problem is now! Good luck! Input Input contains multiple test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains an integer N (1<=N<=1000 the number of integers to be sorted) and then N integers follow in the same line. It is guarantied that all integers are in the range of 32-int. Output For each case, print the sorting result, and one line one case. Sample Input 2 3 2 1 3 9 1 4 7 2 5 8 3 6 9 Sample Output 1 2 3 1 2 3 4 5 6 7 8 9

    #include<iostream> using namespace std; using namespace std; void sort(int arr[],int n) { int x; bool change =true; for(int i = 1;i < n&&change;++i) { change = false; for(int j = 0;j < n - i;++j) { if(arr[j] > arr[j+1]) { x=arr[j]; arr[j] = arr[j+1]; arr[j+1]=x; change = true; } } } } void print(int arr[],int length) { for(int i = 0;i <length;++i) { cout << arr[i]; if(i!=length-1)cout <<" "; } } int main() { int n,num; int cnt = 0; int arr[1001]; cin >> n; while(cin >> num) { for(int i = 0;i < num;++i) cin >> arr[i]; sort(arr,num); print(arr,num); cout << endl; ++cnt; if(cnt==n)break; } system("pause"); return 0; }

    2.The Hardest Problem Ever

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 23252 Accepted Submission(s): 10981

    Problem Description Julius Caesar lived in a time of danger and intrigue. The hardest situation Caesar ever faced was keeping himself alive. In order for him to survive, he decided to create one of the first ciphers. This cipher was so incredibly sound, that no one could figure it out without knowing how it worked. You are a sub captain of Caesar’s army. It is your job to decipher the messages sent by Caesar and provide to your general. The code is simple. For each letter in a plaintext message, you shift it five places to the right to create the secure message (i.e., if the letter is ‘A’, the cipher text would be ‘F’). Since you are creating plain text out of Caesar’s messages, you will do the opposite:

    Cipher text A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

    Plain text V W X Y Z A B C D E F G H I J K L M N O P Q R S T U

    Only letters are shifted in this cipher. Any non-alphabetical character should remain the same, and all alphabetical characters will be upper case.

    Input Input to this problem will consist of a (non-empty) series of up to 100 data sets. Each data set will be formatted according to the following description, and there will be no blank lines separating data sets. All characters will be uppercase.

    A single data set has 3 components:

    Start line - A single line, “START”

    Cipher message - A single line containing from one to two hundred characters, inclusive, comprising a single message from Caesar

    End line - A single line, “END”

    Following the final data set will be a single line, “ENDOFINPUT”.

    Output For each data set, there will be exactly one line of output. This is the original message by Caesar.

    Sample Input START NS BFW, JAJSYX TK NRUTWYFSHJ FWJ YMJ WJXZQY TK YWNANFQ HFZXJX END START N BTZQI WFYMJW GJ KNWXY NS F QNYYQJ NGJWNFS ANQQFLJ YMFS XJHTSI NS WTRJ END START IFSLJW PSTBX KZQQ BJQQ YMFY HFJXFW NX RTWJ IFSLJWTZX YMFS MJ END ENDOFINPUT

    Sample Output IN WAR, EVENTS OF IMPORTANCE ARE THE RESULT OF TRIVIAL CAUSES I WOULD RATHER BE FIRST IN A LITTLE IBERIAN VILLAGE THAN SECOND IN ROME

    #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> using namespace std; char a[205],str[205]; char s[27]={'V','W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U'}; int main() { while(gets(a)) { if(strcmp(a,"ENDOFINPUT")==0) { break; } if(strcmp(a,"START")==0) { gets(str); int len=strlen(str); for(int i=0;i<len;i++) { if(str[i]>='A'&&str[i]<='Z') str[i]=s[str[i]-'A']; } printf("%s\n",str); } } return 0; }

    3.爬C蜗杆 An inch worm is at the bottom of a well n inches deep. It has enough energy to climb u inches every minute, but then has to rest a minute before climbing again. During the rest, it slips down d inches. The process of climbing and resting then repeats. How long before the worm climbs out of the well? We’ll always count a portion of a minute as a whole minute and if the worm just reaches the top of the well at the end of its climbing, we’ll assume the worm makes it out. Input There will be multiple problem instances. Each line will contain 3 positive integers n, u and d. These give the values mentioned in the paragraph above. Furthermore, you may assume d < u and n < 100. A value of n = 0 indicates end of output. Output Each input instance should generate a single integer on a line, indicating the number of minutes it takes for the worm to climb out of the well. Sample Input 10 2 1 20 3 1 0 0 0 Sample Output 17 19

    //Climbing Worm #include <stdio.h> int main() { int n,u,d; int s,m; while (1) { scanf("%d %d %d",&n,&u,&d); if (n == 0 && u == 0 && d == 0) break; s = 0; m = 0; while (1) { s += u; m ++; if (s >= n) break; s -= d; m ++; } printf("%d\n",m); } return 0; }

    4.D - HangOver How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We’re assuming that the cards must be perpendicular to the table.) With two cards you can make the top card overhang the bottom one by half a card length, and the bottom one overhang the table by a third of a card length, for a total maximum overhang of 1/2 + 1/3 = 5/6 card lengths. In general you can make n cards overhang by 1/2 + 1/3 + 1/4 + … + 1/(n + 1) card lengths, where the top card overhangs the second by 1/2, the second overhangs tha third by 1/3, the third overhangs the fourth by 1/4, etc., and the bottom card overhangs the table by 1/(n + 1). This is illustrated in the figure below.

    The input consists of one or more test cases, followed by a line containing the number 0.00 that signals the end of the input. Each test case is a single line containing a positive floating-point number c whose value is at least 0.01 and at most 5.20; c will contain exactly three digits.

    For each test case, output the minimum number of cards necessary to achieve an overhang of at least c card lengths. Use the exact output format shown in the examples. Input 1.00 3.71 0.04 5.19 0.00 Output 3 card(s) 61 card(s) 1 card(s) 273 card(s) Sample Input 1.00 3.71 0.04 5.19 0.00 Sample Output 3 card(s) 61 card(s) 1 card(s) 273 card(s)

    #include<bits/stdc++.h> using namespace std; int cnt(double x) { double s=0; int i=2; while(s<x) { s+=1.0/(i*1.0); ++i; } return i-2; } int main() { double x; while(scanf("%lf",&x),x) { printf("%d card(s)\n",cnt(x)); } return 0; } /* 1.00 3.71 0.04 5.19 0.00 */
    最新回复(0)