首页 > ACM题库 > HDU-杭电 > HDU 1084 What Is Your Grade?-模拟-[解题报告] C++
2013
11-27

HDU 1084 What Is Your Grade?-模拟-[解题报告] C++

What Is Your Grade?

问题描述 :

“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 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 the scores of N students in N lines for each case, and there is a blank line after each case.

样例输入:

4
5 06:30:17
4 07:31:27
4 08:12:12
4 05:23:13
1
5 06:30:17
-1

样例输出:

100
90
90
95

100

题目:点击打开题目链接

模拟题。一场考试一共5道题,满分(都做出来)100,都做不出来50,如果你做对4道,而且做对的时间是所有做对4道题中的人中的前一半及以前(如果4个人做对4个,取前二,如果3个人做对4个,取第一),那么你将获得95分,剩下的人获得90分,同样85,80,75,70……ETC。。

看似挺简单,但是判断二分之一着实还是费了一些功夫的,模拟题都很长。。也很容易出错,还有一个trick。

在仅有1个人做对的情况下,这个人也是要加五分的,但是如果直接无脑除法的话1/2=0,没有人被加5分,就WA了。。除法最好自己写。。

#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <cstring>
using namespace std;

class student
{
public:
    int solve;
    int time;
    int idx;
    int score;
};

int div(int g)
{
	if(g==1)
		return 1;
	else
		return g/2;
}

int wastetime(string tar)
{
    string a,b,c;
    int an,bn,cn,res=0;
    for (int i=0;i<=1;i++)
        a+=tar[i];
    for (int j=3;j<=4;j++)
        b+=tar[j];
    for (int k=6;k<=7;k++)
        c+=tar[k];
    an=atoi(a.c_str());
    bn=atoi(b.c_str());
    cn=atoi(c.c_str());

    res=an*3600+bn*60+cn;
    return res;
}

bool cmp(student c1,student c2)
{
    if (c1.solve!=c2.solve)
        return c1.solve>c2.solve;
    else
        return c1.time<c2.time;
}

bool cmp2(student c1,student c2)
{
    return c1.idx<c2.idx;
}

int main()
{
    student aclass[109];
    int grade[109];
    int countstu[6];
    int testcase;
    while (cin>>testcase && testcase!=-1)
    {
        memset(countstu,0,sizeof(countstu));
        string tar;
        for (int i=0;i<testcase;i++)
        {
            cin>>aclass[i].solve>>tar;

            aclass[i].time=wastetime(tar);
            aclass[i].score=aclass[i].solve*10+50; //第一次处理 先给基础分
            aclass[i].idx=i;
            countstu[aclass[i].solve]++;
        }

        sort(aclass,aclass+testcase,cmp);

        
		int pos=countstu[5];
		
		for(int i=pos;i<pos+div(countstu[4]);i++) //一步一步的慢慢想,不要着急= = 
		{
			aclass[i].score+=5;
		}
		pos+=countstu[4];
		for(int i=pos;i<pos+div(countstu[3]);i++)
		{
			aclass[i].score+=5;
			
		}
		pos+=countstu[3];
		for(int i=pos;i<pos+div(countstu[2]);i++)
		{
			aclass[i].score+=5;
			
		}
		pos+=countstu[2];
		for(int i=pos;i<pos+div(countstu[1]);i++)
		{
			aclass[i].score+=5;
			
		}
		pos+=countstu[1];	

        sort(aclass,aclass+testcase,cmp2);  //处理再给排回去
        for (int i=0;i<testcase;i++)
        {
            cout<<aclass[i].score<<endl;
        }
        
        cout<<endl;

    }
    return 0;
}


  1. 5.1处,反了;“上一个操作符的优先级比操作符ch的优先级大,或栈是空的就入栈。”如代码所述,应为“上一个操作符的优先级比操作符ch的优先级小,或栈是空的就入栈。”

  2. Thanks for using the time to examine this, I truly feel strongly about it and enjoy finding out far more on this subject matter. If achievable, as you achieve knowledge

  3. 站长,你好!
    你创办的的网站非常好,为我们学习算法练习编程提供了一个很好的平台,我想给你提个小建议,就是要能把每道题目的难度标出来就好了,这样我们学习起来会有一个循序渐进的过程!