HDU 1084 What Is Your Grade?

There are 5 problems in this final exam. And I will give you 100 points if you can solve all 5 problems; of course, it is fairly difficulty for many of you. If you can solve 4 problems, you can also get a high score 95 or 90 (you can get the former(前者) only when your rank is in the first half of all students who solve 4 problems). Analogically(以此类推), you can get 85、80、75、70、65、60. But you will not pass this exam if you solve nothing problem, and I will mark your score with 50.
Note, only 1 student will get the score 95 when 3 students have solved 4 problems.

思路:结构体存储数据,先根据分数排序,在每个分数段(除100)根据时间排序,时间在1/2之前的分数加5,再对原来的序号排序,输出。

输出格式:here is a blank line after each case.

附代码

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 using namespace std;
 6 struct Stu {
 7     int num;
 8     int sco;
 9     int tim;
10 };
11 
12 int cmp1(Stu s1,Stu s2) {
13     return s1.tim<s2.tim;
14 }
15 int cmp2(Stu s1,Stu s2) {
16     return s1.num<s2.num;
17 }
18 int cmp3(Stu s1,Stu s2) {
19     return s1.sco>s2.sco;
20 }
21 int main() {
22 
23     freopen("C:\\CODE\\in.txt", "r", stdin);
24     //freopen("C:\\CODE\\out.txt","w",stdout);
25     int n,d,m,s;
26     bool flg=false;
27     char ch[100];
28 
29     while(~scanf("%d",&n)&&n>=1) {
30         getchar();
31         int num[10]= {0};
32         struct Stu stu1[105];
33         for(int i=0; i<n; i++) {
34             gets(ch);
35             stu1[i].num=i+1;
36             stu1[i].sco=(ch[0]-'0')*10+50;
37             d=(ch[2]-'0')*10+(ch[3]-'0');
38             m=(ch[5]-'0')*10+(ch[6]-'0');
39             s=(ch[8]-'0')*10+(ch[9]-'0');
40             stu1[i].tim=d*3600+m*60+s;
41             num[ch[0]-'0']++;
42         }
43         sort(stu1,stu1+n,cmp3);//分数升序
44         int p=num[5];
45         for(int i=4; i>=1; i--) {
46             if(num[i]>=3)
47                 sort(stu1+p,stu1+p+num[i],cmp1);
48             for(int j=0; j<num[i]/2; j++) {
49                 stu1[p+j].sco+=5;
50             }
51             p+=num[i];
52         }
53 
54         sort(stu1,stu1+n,cmp2);
55 
56         flg=true;
57         for(int i=0; i<n; i++) {
58             printf("%d\n",stu1[i].sco);
59             stu1[i].num=0;
60             stu1[i].sco=0;
61             stu1[i].tim=0;
62         }
63         printf("\n");
64     }
65 
66     fclose(stdin);
67     return 0;
68 }

 

posted @ 2016-02-03 13:37  闪耀子  阅读(219)  评论(0编辑  收藏  举报