标签:log for pre turn out memset mem ble str
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084
题目大意:共5道题,N个学生。做出5道满分,0道50分。做出1—4道的同学,若在前50%(向下取整),则获得95、85、75、65,若在后50%则获得90、80、70、60.
关键思想:结构体排序
//结构体排序,考虑边界
#include <iostream>
#include <algorithm>
#include <cmath>
#include <memory.h>
using namespace std;
struct node{
int id;
int n;
int h,m,s;
int score;
}e[102];
int c[6]; //保存做出i题的人数
bool cmps(node a,node b){
return a.n==b.n?(a.h==b.h? (a.m==b.m? a.s<b.s:a.m<b.m):a.h<b.h):a.n>b.n;
}//按题数时间排序
bool cmpid(node a,node b){
return a.id<b.id;
}//按输入ID顺序排序
int main(){
int N,cnt;
while(cin>>N&&N!=-1){
memset(e,0,sizeof(e));
memset(c,0,sizeof(c));
for(int i=0;i<N;i++){
e[i].id=i;
scanf("%d%d:%d:%d",&e[i].n,&e[i].h,&e[i].m,&e[i].s);
c[e[i].n]++;
}
sort(e,e+N,cmps);
cnt=0;
for(int j=0;j<c[5];j++){
e[cnt+j].score=100;
}
cnt+=c[5];
for(int k=4;k>0;k--){
for(int j=0;j<c[k];j++){
if(j<c[k]/2)e[cnt+j].score=50+5*(2*k+1);
else e[cnt+j].score=50+10*k;
}
cnt+=(c[k]);
}
for(int j=0;j<c[0];j++){
e[cnt+j].score=50;
}
sort(e,e+N,cmpid);
for(int i=0;i<N;i++)cout<<e[i].score<<endl;
cout<<endl;
}
return 0;
}
HDU 1084 [What Is Your Grade?] 结构体排序
标签:log for pre turn out memset mem ble str
原文地址:http://www.cnblogs.com/G-M-WuJieMatrix/p/6528518.html