hdu 1084 What Is Your Grade(水题)
2015-08-28 13:55
316 查看
What Is Your Grade?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9540 Accepted Submission(s): 2934
Problem Description
“Point, point, life of student!”
This is a ballad(歌谣)well known in colleges, and you must care about your score in this exam too. How many points can you get? Now, I told you the rules which are used in this course.
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.
I wish you all can pass the exam!
Come on!
Input
Input contains multiple test cases. Each test case contains an integer N (1<=N<=100, the number of students) in a line first, and then N lines follow. Each line contains P (0<=P<=5 number of problems that have been solved) and T(consumed time). You can assume
that all data are different when 0<p.
A test case starting with a negative integer terminates the input and this test case should not to be processed.
Output
Output the scores of N students in N lines for each case, and there is a blank line after each case.
Sample Input
4
5 06:30:17
4 07:31:27
4 08:12:12
4 05:23:13
1
5 06:30:17
-1
Sample Output
100
90
90
95
100
对于qsort函数中的cmp函数不怎么熟导致多次WA
![](http://static.blog.csdn.net/xheditor/xheditor_emot/default/wail.gif)
回顾一下cmp函数:inline int MyCmp(const void* a, const void* b) 都是有两个元素 作为参数,返回一个int 值, 如果 比较函数返回大于0,qsort就认为 a>b , 如果比较函数返回等于0 qsort就认为a 和b 这两个元素相等,返回小于零
qsort就认为 ab),你比较函数却返回一个 -1 (小于零的)那么qsort认为a<本文中排序都是采用的从小到大排序>
代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Node{
int grade;//最后分数
int No;
//同组中的排名
int t;
//作出题目
int time;
int bsNo;
//原始顺序号
}a[120];
int cmp1(constvoid *a,constvoid
*b){ //如果作出题目一样,以time为准小-》大
struct
Node *c=(structNode *)a;
struct
Node *d=(structNode *)b;
if(c->t==d->t)r
4000
eturn c->time-d->time;
return d->t - c->t;
}
int cmp2(const
void *a,const
void *b) //返回初始顺序
{
struct
Node *c=(structNode *)a;
struct
Node *d=(structNode *)b;
return c->bsNo-d->bsNo;
}
int main()
{
int rs[6];
int N;
while (scanf("%d",&N)!=EOF&&N>=0)
{
memset(rs,
0,sizeof(rs));
for (int i=0; i<N; i++) {
int m,s,h;
scanf("%d %d:%d:%d",&a[i].t,&h,&m,&s);
a[i].time = h*3600+m*60+s;
rs[a[i].t]++;
a[i].bsNo=i;
}
qsort(a, N,sizeof(a[0]),cmp1);
a[0].No=1;
for (int i=1; i<N; i++) {
a[i].No=1;
if(a[i].t==a[i-1].t)
a[i].No+=a[i-1].No;
}
for (int i=0; i<N; i++) {
a[i].grade=a[i].t*10+50;
if((a[i].t>=1&&a[i].t<5)&&a[i].No<=rs[a[i].t]/2)
a[i].grade+=5;
}
qsort(a, N,sizeof(a[0]),cmp2);
for (int i=0; i<N; i++) {
printf("%d\n",a[i].grade);
}
printf("\n");
}
return
0;
}
相关文章推荐
- 打包签名与版本号修改
- 数据结构和算法基础
- nim的引用和指针
- 每日python(4)
- [Leetcode]House Robber
- java POI实现向Excel中插入图片
- Android性能优化典范(一)
- chrome使用技巧
- (11)QInputDialog--输入对话框
- 编程一开始就应该养成的好习惯
- 总结1-JMeter压力测试
- C++11新特性浅析
- C标准库 io.h源码 检查文件是否存在
- vi/vim 注释字体颜色的设置
- 用浏览器跳转APP研究方案记录
- 九度题目1384:二维数组中的查找
- Windows系统下,查看端口占用情况杀掉端口占用进程
- 关于 mysql中非null判断
- 字符0D再度惹出麻烦
- Mac Book 上安装Windows 8 / 10 以后安装 Hyper-v 无法正常使用问题---虚拟化已禁止问题