hdu 2142 disney(模拟)
来源:互联网 发布:怎么在淘宝开养生店 编辑:程序博客网 时间:2024/05/22 14:35
比赛的时候这个题目一直做不出来,WA了很多遍。比赛结束之后看别人的代码,发现竟然还需要排序!
经过我长久的思考,我终于发现了问题的所在,原来题目中的Lexicographicly是字典序的意思,这特么的!
排序之后,AC。
#include<stdio.h>#include<string.h>#include<stdlib.h>struct node{ char name[15]; int score; int id;}map[10005];int cmp(const void *a,const void *b){ if((*(node *)a).score!=(*(node *)b).score) return (*(node *)a).score-(*(node *)b).score; else return strcmp((*(node *)a).name,(*(node *)b).name);}int main(){ char NEW[15]={"NEW"},MAX[15]={"MAX"},AVE[15]={"AVERAGE"},DEL[15]={"DELETE"},QT[15]={"QUIT"}; int count; char s[1005],s1[1005]; int i; int temp,max; int sum; int t; int flag; count=0; for(i=0;i<=1005;i++) { map[i].id=-1; map[i].score=-1; } lab: while(1) { scanf("%s",s); if(strcmp(NEW,s)==0) { scanf("%s%d",s1,&temp); for(i=0;i<count;i++) { if(map[i].id!=-1&&strcmp(map[i].name,s1)==0) { map[i].score=temp; printf("update succeed\n"); getchar(); goto lab; } } for(i=0;i<count;i++) { if(map[i].id==-1) { strcpy(map[i].name,s1); map[i].id=1; map[i].score=temp; printf("A new record\n"); getchar(); goto lab; } } strcpy(map[count].name,s1); map[count].id=1; map[count].score=temp; count++; getchar(); printf("A new record\n"); goto lab; } if(strcmp(s,MAX)==0) { max=-1; if(count!=0) qsort(map,count,sizeof(map[0]),cmp); for(i=0;i<count;i++) { if(map[i].score>max&&map[i].id!=-1) max=map[i].score; } if(max==-1) { printf("0 0\n"); getchar(); goto lab; } printf("%d ",max); t=0; for(i=0;i<count;i++) { if(map[i].score==max&&map[i].id!=-1) t++; } printf("%d\n",t); for(i=0;i<count;i++) { if(map[i].score==max&&map[i].id!=-1) puts(map[i].name); } getchar(); goto lab; } if(strcmp(s,AVE)==0) { sum=0; t=0; for(i=0;i<count;i++) { if(map[i].id!=-1) { sum+=map[i].score; t++; } } if(t==0) { printf("0.00\n"); getchar(); goto lab; } else { printf("%.2f\n",sum*1.0/t); getchar(); goto lab; } } if(strcmp(s,DEL)==0) { flag=0; scanf("%s",s1); for(i=0;i<count;i++) { if(strcmp(s1,map[i].name)==0&&map[i].id!=-1) { map[i].id=-1; flag=1; } } if(flag==1) printf("delete succeed\n"); else printf("no such record\n"); getchar(); goto lab; } if(strcmp(s,QT)==0) break; } return 0; }
- hdu 2142 disney(模拟)
- hdu 1242 disney (map模拟)
- HDU 2142 - disney
- hdu 2142 disney
- disney (map模拟)
- HDU Disney's FastPass
- hdu Disney's FastPass(状态压缩dp)
- Hdu 4114 Disney's FastPass(状压dp)
- HDU Disney's FastPass(状态压缩DP)
- HDU 4114 Disney's FastPass(floyd+状态压缩DP)
- hdu 4114 Disney's FastPass
- Disney
- hdu 2142 (模拟,,,)
- HDU 4114 Disney's FastPass(状压dp)
- hdu 4114 Disney's FastPass 状压dp
- HDU 4114 Disney's FastPass Time
- hdu 4114 Disney's FastPass 状压dp+floyd
- hdu 3347(模拟)
- 在Myeclipse中配置tomcat
- spfa() 先辈们好给力啊!orz...... come on!
- 379. Something is better than nothing. 聊胜于无
- Extjs 4.0 ajax请求超时,php请求超时,excel读取时php提示内存不足。
- 2013南阳理工acm校赛总结
- hdu 2142 disney(模拟)
- 黑马程序员——常用的数据库操作
- javascript创建对象的几种方式
- acm常见问题
- 使用JSCH连接Linux服务器-执行linux命令
- 随机组队赛 Diligent Boys Don’t Love 终于AC了。 我知错了。。。555
- light oj 1047 - Neighbor House 动态规划
- JQuery学习(2)选择器(2)
- GetVersion和GetVersionEx