hdu 1236 排序

来源:互联网 发布:音视频格式转换软件 编辑:程序博客网 时间:2024/05/22 11:42

hdu  1236  排序                    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1236

贪心水

题目分析:无tricker水,贪心即可。

code:

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;struct node{char id[30];int score; }examinee[1050];int cmp(node a,node b){if(a.score!=b.score)return a.score>b.score?1:0;else return strcmp(a.id,b.id)<0?1:0;}int main(){int n,m,i,j,g,problem[20],flag,temp,cnt;char c[20][20],query[20][20];while(scanf("%d",&n)!=EOF,n){cnt=0;scanf("%d%d",&m,&g);for(i=1;i<=m;i++){scanf("%d",&problem[i]);}for(i=0;i<n;i++){scanf("%s %d",examinee[i].id,&flag);examinee[i].score=0;for(j=0;j<flag;j++){scanf("%d",&temp);examinee[i].score+=problem[temp];}if(examinee[i].score>=g)cnt++;}sort(examinee,examinee+n,cmp);printf("%d\n",cnt);for(i=0;i<n;i++){if(examinee[i].score<g)break;printf("%s %d\n",examinee[i].id,examinee[i].score);}}}
PS:4wrong带5Compile Error,自己学了学qsort,自己这边样例都过了,一交居然不认已经定义的结构体类型,typedef也没用,无语……wrong是因为没看见输出还要先有一个通过人数……