The 16th Zhejiang University Programming Contest

A——Programming Ability Test

Programming Ability Test (PAT) aims to evaluate objectively, through unified examinations with automatic online judging system, the abilities of testees in programming and algorithm design, hence to evaluate scientifically the programming talents, and to provide the enterprises a reference standard for personnel selection.

The alliance enterprises may have their specific green channel preferential conditions listed at the PAT registration website. Some enterprises also provide “Letter of Introduction” for the testees to download and submit to the human resource department together with the PAT certificate when seeking employments.

Recently, Edward Co.,LTD joins PAT Alliance and sets their green channel preferential conditions to 80 points of PAT Advanced Level. That means you can enter the green channel if you get 80 points or above on PAT Advanced Level. Now Edward Co.,LTD gets the result of all examinees, please tell them whether the examinee can get the chance of entering green channel.

Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The only line contains four integers ScoreA, ScoreB, ScoreC, and ScoreD - the four problems' score of the examinee.(0 <= ScoreA <= 20, 0 <= ScoreB, ScoreC <= 25, 0 <= ScoreD <= 30)

Output

For each test case, if the examinee gets 80 points or above in total, output "Yes", else output "No".

Sample Input

4
0 0 5 30
20 25 20 0
20 25 20 15
20 25 25 30

Sample Output

No
No
Yes
Yes

题意:判断给出的四个数和是否达到八十。
 1 /*A*/
 2 #include<cstdio>
 3 using namespace std;
 4 int main()
 5 {
 6     int T;
 7     scanf("%d",&T); 
 8     while(T--)
 9     {
10         int a,b,c,d;
11         scanf("%d%d%d%d",&a,&b,&c,&d);
12         if((a+b+c+d)>=80)
13             printf("Yes
");
14         else
15             printf("No
");
16     }
17     return 0;
18  } 
View Code

B——Handshakes

Last week, n students participated in the annual programming contest of Marjar University. Students are labeled from 1 to n. They came to the competition area one by one, one after another in the increasing order of their label. Each of them went in, and before sitting down at his desk, was greeted by his/her friends who were present in the room by shaking hands.

For each student, you are given the number of students who he/she shook hands with when he/she came in the area. For each student, you need to find the maximum number of friends he/she could possibly have. For the sake of simplicity, you just need to print the maximum value of the n numbers described in the previous line.

Input

There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

The first line contains an integer n (1 ≤ n ≤ 100000) -- the number of students. The next line contains n integers a1, a2, ..., an (0 ≤ ai < i), where ai is the number of students who the i-th student shook hands with when he/she came in the area.

Output

For each test case, output an integer denoting the answer.

Sample Input

2
3
0 1 1
5
0 0 1 1 1

Sample Output

2
3

题意:有n个人依次进入考场,如果考场中有他的朋友,那么他的朋友则会和他到招呼。现在输入每个人进门时与他打招呼的人数,求这n个人中,朋友最多的那个人,他的朋友数量最多可能有多少个?
题解:用max来记录已经进入考场的人中朋友数量可能达到的最大值。对第i个人,只要有人和他打招呼,那么max++,之后再判断有多少人与他打了招呼,这个数值可能会比max大,所以max要取两个数中较大的一个
 1 /*F*/
 2 #include<cstdio>
 3 #include<cstring>
 4 using namespace std;
 5 
 6 const int maxn=100000+100;
 7 int main()
 8 {
 9     int T;
10     scanf("%d",&T);
11     while(T--)
12     {
13         int n;
14         int a[maxn];
15         int max=0;
16         scanf("%d",&n);
17         for(int i=0;i<n;i++)
18         {
19             scanf("%d",&a[i]);
20             if(a[i])
21                 max++;
22             if(a[i]>max)
23                max=a[i];
24         }
25         printf("%d
",max);
26     }
27     return 0;
28 }
View Code

I——2016

In mathematics, a polygonal number is a number represented as dots or pebbles arranged in the shape of a regular polygon. The dots are thought of as alphas (units). These are one type of 2-dimensional figurate numbers. The following picture shows how triangular numbers, square numbers, pentagonal numbers and hexagonal numbers represented as dots arranged in the shape of corresponding regular polygon.

Polygonal Numbers: Triangular, Square, Pentagonal and Hexagonal numbers

2016 is not only a leap year but also a triangular and hexagonal year. If you are patient enough, you can count the number of the dots in the left triangle or in the right hexagon in the following picture. The number of dots in each shape is 2016.

2016 is a triangular-hexagonal-leap year

Therefore, 2016 is a triangular-hexagonal-leap year. The previous triangular-hexagonal-leap year is 1540 and the next is 2556. So living to see 2016 is very rare experience.

You task is to list the triangular-hexagonal-leap years from 2016 to 990528. 990528 is also a triangular-hexagonal-leap year.

Input

This problem has no input.

Output

Please print each triangular-hexagonal-leap year in increasing order.

For example, if you are asked to list the triangular-hexagonal-leap years from 780 to 2556, the output should be:

780
1128
1540
2016
2556

Sample Output

2016
2556
...  <-- some lines are skipped
990528

题意:问2016到990528之间有哪些数,是瑞年且满足n(3n-1)/2和n(2n-1)这两个公式。

题解:先打两个表,找出满足那两个公式的值。然后从2016开始依次判断(二分查找),满足条件则输出。

 1 /*I*/
 2 #include<cstdio>
 3 using namespace std;
 4 
 5 int a[10000],b[10000];
 6 int lena=1408,lenb=705;
 7 void First()
 8 {
 9     for(int i=1;;i++)
10     {
11         a[i]=i*(i+1)/2;
12         if(a[i]>990528)    
13         {
14             lena=i;
15             break;
16         }
17     }    
18     for(int i=1;;i++)
19     {
20         b[i]=i*(2*i-1);
21         if(b[i]>990528)
22         {
23             lenb=i;
24             break;
25         }
26     }
27 }
28 
29 int find_a(int n,int l,int r)
30 {
31     if(l==r)
32     {
33         if(n==a[l])
34             return 1;
35         else
36             return 0;
37     }
38     int mid=(l+r)/2;
39     if(n>a[mid])
40         return find_a(n,mid+1,r);
41     else 
42         return find_a(n,l,mid); 
43 }
44 
45 int find_b(int n,int l,int r)
46 {
47     if(l==r)
48     {
49         if(n==b[l])
50             return 1;
51         else
52             return 0;
53     }
54     int mid=(l+r)/2;
55     if(n>b[mid])
56         return find_b(n,mid+1,r);
57     else 
58         return find_b(n,l,mid); 
59 }
60 
61 int isleap(int n)
62 {
63     int flag=0;
64     if(n%4==0)
65         flag=1;
66     if(n%100==0)
67         flag=0;
68     if(n%400==0)
69         flag=1;
70     return flag;
71 }
72 
73 int main()
74 {
75     First();
76     for(int i=2016;i<=990528;i++)
77     {
78         if(isleap(i))
79         {
80             if(find_a(i,1,1407)&&find_b(i,1,704))
81                 printf("%d
",i);
82         }
83     }
84     return 0;
85 }
View Code
原文地址:https://www.cnblogs.com/yepiaoling/p/5384072.html