庆师模拟7

来源:互联网 发布:google json插件 编辑:程序博客网 时间:2024/04/30 20:19

 

Ignatius and the Princess IV

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32767K (Java/Other)
Total Submission(s) : 23   Accepted Submission(s) : 6

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

"OK, you are not too bad, em... But you can never pass the next test." feng5166 says.

"I will tell you an odd number N, and then N integers. There will be a special integer among them, you have to tell me which integer is the special one after I tell you all the integers." feng5166 says.

"But what is the characteristic of the special integer?" Ignatius asks.

"The integer will appear at least (N+1)/2 times. If you can't find the right integer, I will kill the Princess, and you will be my dinner, too. Hahahaha....." feng5166 says.

Can you find the special integer for Ignatius?

Input

The input contains several test cases. Each test case contains two lines. The first line consists of an odd integer N(1<=N<=999999) which indicate the number of the integers feng5166 will tell our hero. The second line contains the N integers. The input is terminated by the end of file.

Output

For each test case, you have to output only one line which contains the special number you have found.

Sample Input

51 3 2 3 3111 1 1 1 1 5 5 5 5 5 571 1 1 1 1 1 1

Sample Output

351
第一题,第一眼没思路。第二眼还是没思路。然后就跳过去了。等到最后看答案的时候竟然这么简单,略坑~~~
输出要用scanf,cin超时
 
#include<iostream>#include<cstdio>#include<string>using namespace std;int a[500000+4];int main(){int n;while(cin>>n){int i;int b,count;memset(a,0,sizeof(a));for(i=0;i<n;i++){scanf("%d",&b);a[b]++;if(a[b]>=(n+1)/2) count=b;}printf("%d\n",count);}return 0;}
 
 
 

AC Me

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 19   Accepted Submission(s) : 10

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

Ignatius is doing his homework now. The teacher gives him some articles and asks him to tell how many times each letter appears.It's really easy, isn't it? So come on and AC ME.

Input

Each article consists of just one line, and all the letters are in lowercase. You just have to count the number of each letter, so do not pay attention to other characters. The length of article is at most 100000. Process to the end of file.Note: the problem has multi-cases, and you may use "while(gets(buf)){...}" to process to the end of file.

Output

For each article, you have to tell how many times each letter appears. The output format is like "X:N". Output a blank line after each test case. More details in sample output.

Sample Input

hello, this is my first acm contest!work hard for hdu acm.

Sample Output

a:1b:0c:2d:0e:2f:1g:0h:2i:3j:0k:0l:2m:2n:1o:2p:0q:0r:1s:4t:4u:0v:0w:0x:0y:1z:0a:2b:0c:1d:2e:0f:1g:0h:2i:0j:0k:1l:0m:1n:0o:2p:0q:0r:3s:0t:0u:1v:0w:1x:0y:0z:0
 

第二题不解释。水题一道;
#include<iostream>#include<string>using namespace std;char buf[100000];int main(){        while(gets(buf))    {        int len=strlen(buf);        int count;                   for(char i='a';i<='z';i++)                {                    count=0;                      for(int j=0;j<len;j++)                   {                     if(buf[j]==i)                     count++;                    }                    cout<<i<<":"<<count<<endl;             }        cout<<endl;     }    return 0;}
 

The 3n + 1 problem

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 16   Accepted Submission(s) : 9

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

Problems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.Consider the following algorithm:     1.      input n    2.      print n    3.      if n = 1 then STOP    4.           if n is odd then n <- 3n + 1    5.           else n <- n / 2    6.      GOTO 2Given the input 22, the following sequence of numbers will be printed 22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1 It is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers n such that 0 < n < 1,000,000 (and, in fact, for many more numbers than this.) Given an input n, it is possible to determine the number of numbers printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j.

Input

The input will consist of a series of pairs of integers i and j, one pair of integers per line. All integers will be less than 1,000,000 and greater than 0. You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including i and j. You can assume that no opperation overflows a 32-bit integer.

Output

For each pair of input integers i and j you should output i, j, and the maximum cycle length for integers between and including i and j. These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers i and j must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).

Sample Input

1 10100 200201 210900 1000

Sample Output

1 10 20100 200 125201 210 89900 1000 174
 
 
第三题,还好。算法已经给出了。只是忽略一个问题。i和j并不是冲小到大输入的,所以之前老师WA。
还有这个题不好。输入大的数据没有输出。尽管AC
#include<stdio.h>int t;int f(int x){    t=1;    while(x!=1)    {        if(x%2==0)            x=x/2;        else x=3*x+1;        t++;    }    return t;}int main(){    int m,n,begin,end;    while(scanf("%d%d",&m,&n)!=EOF)    {        if(m>n)        {           begin=n;           end=m;        }        else        {            begin=m;            end=n;        }            int max=-1;            for(int i=begin; i<=end; i++)            {                if(max<f(i))                    max=f(i);            }            printf("%d %d %d\n",m,n,max);    }    return 0;}
 

Keep on Truckin'

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 31   Accepted Submission(s) : 21

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

Boudreaux and Thibodeaux are on the road again . . ."Boudreaux, we have to get this shipment of mudbugs to Baton Rouge by tonight!""Don't worry, Thibodeaux, I already checked ahead. There are three underpasses and our 18-wheeler will fit through all of them, so just keep that motor running!""We're not going to make it, I say!"So, which is it: will there be a very messy accident on Interstate 10, or is Thibodeaux just letting the sound of his own wheels drive him crazy?

Input

Input to this problem will consist of a single data set. The data set will be formatted according to the following description.The data set will consist of a single line containing 3 numbers, separated by single spaces. Each number represents the height of a single underpass in inches. Each number will be between 0 and 300 inclusive.

Output

There will be exactly one line of output. This line will be:   NO CRASHif the height of the 18-wheeler is less than the height of each of the underpasses, or:   CRASH Xotherwise, where X is the height of the first underpass in the data set that the 18-wheeler is unable to go under (which means its height is less than or equal to the height of the 18-wheeler). The height of the 18-wheeler is 168 inches.

Sample Input

180 160 170

Sample Output

CRASH 160

Source

South Central USA 2003 

 
水题。不多说
#include<iostream>using namespace std;int main(){int x,y,z;while(cin>>x>>y>>z){if(x<=168)  cout<<"CRASH "<<x;  else    if(y<=168)      cout<<"CRASH "<<y;     else   if(z<=168)        cout<<"CRASH "<<z;          else            cout<<"NO CRASH";            cout<<endl;}return 0;}

As Easy As A+B

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 27   Accepted Submission(s) : 14

Font: Times New Roman | Verdana | Georgia

Font Size:

Problem Description

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

23 2 1 39 1 4 7 2 5 8 3 6 9

Sample Output

1 2 31 2 3 4 5 6 7 8 9

Author

lcy

 
水题,不多说
 
#include<iostream>#include<algorithm>using namespace std;int a[1000+5];int main(){int n;while(cin>>n){while(n--){int t;cin>>t;  int i;    for(i=0;i<t;i++)    cin>>a[i];    sort(a,a+t);    for(i=0;i<t-1;i++)    cout<<a[i]<<" ";    cout<<a[i]<<endl;}}return 0;}

 
总结:就算第一题还算比较好!
0 0
原创粉丝点击