您的位置:首页 > 编程语言 > Go语言

hdu1084:What is your grade?

2014-11-05 13:36 489 查看
题目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=1084

这道题要注意只有一个人做4.3.2.1道题时是90.80,70,60分,因为这坑了我好久!

还有注意下排序就OK了,简直水得不能再水了!

上AC代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<queue>
#include<iomanip>
using namespace std;

const int maxn = 101;
struct Student{
int num;
int ID;
int time;
}st[maxn];

int ranks[4][2] = { { 65, 60 }, { 75, 70 }, { 85, 80 },{ 95, 90 } };

bool cmp(const Student &s1, const Student &s2){
return s1.num > s2.num || (s1.num == s2.num&&s1.time < s2.time);
}
int main(){
int n, a, b, c;
int T;
while (cin >> T, T != -1){
int i, j,t;
for (i = 0; i < T;i++){
scanf("%d %d:%d:%d", &n, &a, &b, &c);
int time = a * 60 * 60 + b * 60 + c;
st[i].ID = i;
st[i].num = n;
st[i].time = time;
}
sort(st, st + T, cmp);
int score[maxn];
int num = 0;
j=0;
int end=0;
int pres = -1;
bool flag1=false;
bool flag = false;
for (i = 0; i < T; i++){
if (st[i].num == 5){
score[st[i].ID] = 100;
}
else if(st[i].num==0){
if(flag&&!flag1){
end=i;
flag1=true;
}
score[st[i].ID] = 50;
}
else if(pres==st[i].num){
num++;
end=i+1;
flag=true;
}
else{
if(flag){
int mid = num / 2;
for (t = j; t < j+mid; t++){
score[st[t].ID] = ranks[st[t].num - 1][0];
}
for (t = j + mid; t < i; t++){
score[st[t].ID] = ranks[st[t].num - 1][1];
}
}
num = 1;
pres = st[i].num;
score[st[i].ID]=ranks[st[i].num-1][1];
j = i;
flag=false;
}
}
if(flag&&j<end){
int mid = num / 2;
for (t = j; t < j+mid; t++){
score[st[t].ID] = ranks[st[t].num - 1][0];
}
for (t = j + mid; t < end; t++){
score[st[t].ID] = ranks[st[t].num - 1][1];
}
}
for (i = 0; i < T; i++){
printf("%d\n", score[i]);
}
printf("\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  algorithm