hdu 1084 What Is Your Grade?

题目地址:

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

题目描述:

What Is Your Grade?

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7528    Accepted Submission(s): 2329


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

题意:

成绩打分,答对5题的一律100分 答对0题的一律50分,其他情况看当前相同答题数量的人数中的排名酌情给分。

题解:

将输入按照 优先级 答题数〉小时〉分钟〉秒数 排序。然后根据将排序后的列表扫描,依次从答对题数量 和 排名给出分数。

错因:

在函数GetScore()中 计算每一个下标i 对应的 搜索下标 j 的搜索起点j的计算 算错了  方向算反了  应该是 5 ~ 目标 num  而不是 0 ~ 目标num,比如 i 的 num是4  就直接将 j 定位到4开始扫描 而不用从 5 那一类 扫描到 4。(利用自主生成海量数据 测试 代码 找到了bug点)

代码:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
int N=0;//number of the students
typedef struct ScoreList
{
	int num;
	int hours;
	int mins;
	int secs;
	int score;
	ScoreList()
	{
		num=0;
		hours=0;
		mins=0;
		secs=0;
		score=0;
	}
}ScoreList,*ScoreListLink;
ScoreList InputList[100+5];
ScoreList SortList[100+5];
int ProbNum[6]={0};//0 1 2 3 4 5 problem  have the number of the student
int MapScore[6]={50,65,75,85,95,100};//the map for problem num to score
/*for test*/
int test()
{
	int n=50,i=0,j=0;
	for(i=0;i<=n-1;i++)
	{
		N=rand()%100+1;
		printf("%d\n",N);
		int P=0;
		int hours=0;
		int mins=0;
		int secs=0;
		for(j=0;j<=N-1;j++)
		{
			P=rand()%6;
			hours=rand()%11;
			mins=rand()%60;
			secs=rand()%60;
			printf("%d %02d:%02d:%02d\n",P,hours,mins,secs);
		}
	}
	printf("-1\n");
	return(0);
}
/*compare for the sort*/
bool cmp(ScoreList a,ScoreList b)
{
	if(a.num>b.num)
	{
		return(true);
	}
	else if(a.num<b.num)
	{
		return(false);
	}
	else//num equal
	{
		if(a.hours<b.hours)
		{
			return(true);
		}
		else if(a.hours>b.hours)
		{
			return(false);
		}
		else//hours equal
		{
			if(a.mins<b.mins)
			{
				return(true);
			}
			else if(a.mins>b.mins)
			{
				return(false);
			}
			else//min equal
			{
				return(a.secs<b.secs);
			}
		}
	}
}
/*get the SortList score*/
int GetSortScore()
{
	int i=0,ith=0,num=0;//ith is the rank of the same solved problem number,num is 0~5
	ith=1;
	num=SortList[i].num;
	SortList[i].score=MapScore[num];
	for(i=1;i<=N-1;i++)
	{
		if(num!=SortList[i].num)
		{
			//first !=
			ith=1;
			num=SortList[i].num;
			SortList[i].score=MapScore[num];
		}
		else//num is same
		{
			ith++;
			SortList[i].score=MapScore[num];
			if((num>=1&&num<=4)&&ith>ProbNum[num]/2)
			{
				SortList[i].score-=5;
			}
		}
	}
	return(0);
}
/*judge the equal of the time and num  no score elementary*/
bool IsEqual(ScoreList &a,ScoreList &b)
{
	if(a.num==b.num&&a.hours==b.hours&&a.mins==b.mins&&a.secs==b.secs)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}
/*according to the SortList , we make the ScoreList 's  score elementary*/
int GetScore()
{
	int i=0,j=0;//j is the start search for the SortList
	for(i=0;i<=N-1;i++)
	{
		j=0;
		int num=5;
		while(num>InputList[i].num)
		{
			j+=ProbNum[num];
			num--;
		}
		for(;j<=N-1;j++)
		{
			if(IsEqual(InputList[i],SortList[j]))
			{
				InputList[i].score=SortList[j].score;
				break;
			}
		}
	}
	return(0);
}
/*main process*/
int MainProc()
{
	while(scanf("%d",&N)!=EOF&&N>=0)
	{
		//initialze
		memset(ProbNum,0,sizeof(ProbNum));
		int i=0;
		for(i=0;i<=N-1;i++)
		{
			scanf("%d %d:%d:%d",&InputList[i].num,&InputList[i].hours,&InputList[i].mins,&InputList[i].secs);
			SortList[i].num=InputList[i].num;
			SortList[i].hours=InputList[i].hours;
			SortList[i].mins=InputList[i].mins;
			SortList[i].secs=InputList[i].secs;
			ProbNum[InputList[i].num]++;
		}
		//sort and get the score
		sort(SortList,SortList+N,cmp);
		GetSortScore();
		GetScore();//runtime error!!
		//output score
		for(i=0;i<=N-1;i++)
		{
			printf("%d\n",InputList[i].score);
		}
		printf("\n");
	}
	return(0);
}
int main()
{
	MainProc();
	//test();
	return(0);
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值