8月9号水题走一波(晚上)-个人赛七

1.The Rank

Description

John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.There are n students, each of them has a unique id (from 1 to n). Thomas's id is 1. Every student has four scores correspond to his or her English, German, Math, and History scores. The students are given in order of increasing of their ids.In the table, the students will be sorted by decreasing the sum of their scores. So, a student with the largest sum will get the first place. If two or more students have the same sum, these students will be sorted by increasing their ids.Please help John find out the rank of his son.

Input

The first line contains a single integer n(1≤n≤1000) — the number of students.
Each of the next n lines contains four integers ai, bi, ci, and di (0≤ai,bi,ci,di≤100) — the grades of the i-th student on English, German, Math, and History. The id of the i-th student is equal to i.

Output
Print the rank of Thomas Smith. Thomas's id is 1.

Sample Input
Input


5
100 98 100 100
100 100 100 100
100 100 99 99
90 99 90 100
100 98 60 99

Output

2

Input

6
100 80 90 99
60 60 60 60
90 60 100 60
60 100 60 80
100 100 0 100
0 0 0 0

Output

1

Hint

In the first sample, the students got total scores: 398, 400, 398, 379, and 357. Among the 5 students, Thomas and the third student have the second highest score, but Thomas has a smaller id, so his rank is 2.

In the second sample, the students got total scores: 369, 240, 310, 300, 300, and 0. Among the 6 students, Thomas got the highest score, so his rank is 1.

 

题目意思:主人公的学号是1也就是第一组输入的各科成绩,计算出成绩的总和与后面的学生成绩的总和对比一下就行了。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     int a,b,c,d,counts,sum,i;
 9     scanf("%d",&n);
10     counts=1;
11     scanf("%d%d%d%d",&a,&b,&c,&d);
12     sum=a+b+c+d;
13     for(i=1;i<n;i++)
14     {
15         scanf("%d%d%d%d",&a,&b,&c,&d);
16         if(sum<a+b+c+d)
17         {
18             counts++;
19         }
20 
21     }
22     printf("%d\n",counts);
23 }

 

2.Death Note

Description

You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i-th day you have to write exactly ai names.". You got scared (of course you got scared, who wouldn't get scared if he just receive a notebook which is named Death Note with a some strange rule written in it?).Of course, you decided to follow this rule. When you calmed down, you came up with a strategy how you will write names in the notebook. You have calculated that each page of the notebook can contain exactly m names. You will start writing names from the first page. You will write names on the current page as long as the limit on the number of names on this page is not exceeded. When the current page is over, you turn the page. Note that you always turn the page when it ends, it doesn't matter if it is the last day or not. If after some day the current page still can hold at least one name, during the next day you will continue writing the names from the current page.Now you are interested in the following question: how many times will you turn the page during each day? You are interested in the number of pages you will turn each day from 1 to n.

Input

The first line of the input contains two integers n, m (1≤n≤2⋅105, 1≤m≤109) — the number of days you will write names in the notebook and the number of names which can be written on each page of the notebook.

The second line contains n integers a1,a2,…,an (1≤ai≤109), where ai means the number of names you will write in the notebook during the i-th day.

Output

Print exactly n integers t1,t2,…,tn, where ti is the number of times you will turn the page during the i-th day.

Sample Input
Input

3 5
3 7 9

Output

0 2 1

Input

4 20
10 9 19 2

Output

0 0 1 1

Input

1 100
99

Output

0

Hint

In the first example pages of the Death Note will look like this [1,1,1,2,2],[2,2,2,2,2],[3,3,3,3,3],[3,3,3,3]. Each number of the array describes during which day name on the corresponding position will be written. It is easy to see that you should turn the first and the second page during the second day and the third page during the third day.

 

题目意思:给你一本死亡日记,要在n天内,每天都要往上写名字,死亡日记每一页一共可以写m个名字,问你每天需要翻的页数。

解题思路:模拟一下。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<string>
 4 #include<iostream>
 5 #include<algorithm>
 6 const int MAX=2e5+10;
 7 using namespace std;
 8 int a[MAX];
 9 int ans[MAX];
10 int main()
11 {
12    int n,m,x,y,i;
13    scanf("%d%d",&n,&m);
14    x=0;
15    y=m;
16    for(i=0;i<n;i++)
17    {
18        scanf("%d",&a[i]);
19    }
20    for(i=0;i<n;i++)
21    {
22        if(a[i]<y)///不足以翻页
23        {
24            y=y-a[i];///不满的行数
25            ans[i]=0;
26        }
27        else
28        {
29            a[i]=a[i]-y;
30            ans[i]++;
31            y=m-a[i]%m;
32            x=a[i]/m;
33            ans[i]=ans[i]+x;
34        }
35    }
36    for(i=0;i<n;i++)
37    {
38        if(a[i]==n-1)
39        {
40            printf("%d\n",ans[i]);
41        }
42        else
43        {
44            printf("%d ",ans[i]);
45        }
46    }
47    return 0;
48 }

 

posted @ 2018-08-10 09:48  王陸  阅读(503)  评论(0编辑  收藏  举报