HDOJ What is your grade?

题目:

 

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

比较简单的一道题目……首先根据耗时和解决题目的数量进行排序,然后根据题目要求进行分数换算,这里面if语句的顺序弄反了让我提交了好几次才ac...

最后再根据输入位置进行排序输出...

写的有点麻烦

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct Student
{
    int p;
    string s;
    int grade;
    int order;
};
bool cmp(const Student&a,const Student&b)
{
    if(a.p!=b.p)
        return a.p>b.p;
    else
        return a.s<b.s;
}
bool cmp2(const Student&a,const Student&b)
{
    return a.order<b.order;
}
int main()
{
    int n;
    while(scanf_s("%d",&n)&&n>0)
    {
        vector<Student> t;
        Student temp;
        int k=n;
        temp.p=100;
        t.push_back(temp);
        int j=0;
        int count[6]={0};
        while(n--)
        {
            cin>>temp.p>>temp.s;
            temp.order=j++;
            t.push_back(temp);

        }
        sort(t.begin()+1,t.end(),cmp);
        //temp.p=100;
        //t.push_back(temp);
        for (int i = 1; i < k+1; i++)
        {
            count[t[i].p]++;
        }
        for (int i = 0; i < 6; i++)
        {
            count[i]==1?count[i]=-5:count[i]/=2;
        }
        for (int i = 1; i < k+1; i++)
        {
            if(count[t[i].p]==-5)
                t[i].grade=50+t[i].p*10+5;
            if (count[t[i].p]==0)
            {
                t[i].grade=50+t[i].p*10;
            }
            if(count[t[i].p]>0)
            {
                t[i].grade=50+t[i].p*10+5;
                count[t[i].p]--;
            }

            if(t[i].p==5||t[i].p==0)
                t[i].grade=50+t[i].p*10;
        }
        sort(t.begin()+1,t.end(),cmp2);
        for (int i = 1; i < k+1; i++)
        {
            cout<<t[i].grade<<endl;
        }
        cout<<endl;
    }
    return 0;
}
时间: 2024-12-27 16:33:55

HDOJ What is your grade?的相关文章

hdoj 2586 How far away ? 【Tarjan离线LCA】

题目:hdoj 2586 How far away ? 题意:给出一个有权树,求任意两点的之间的距离. 分析:思想就是以一个点 root 作为跟变成有根数,然后深搜处理处所有点到跟的距离.求要求的两个点的LCA(最近公共祖先), 然后ans = dis[x] + dis[y] - 2 * dis[LCA(x,y)],可以画图分析一下就知道. 求LCA我用的是Tarjan离线lca,由于询问次数很多,所以这个比较快. AC代码: #include <iostream> #include <

Hdoj 2586 How far away ? 【LCA】

How far away ? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7072 Accepted Submission(s): 2575 Problem Description There are n houses in the village and some bidirectional roads connecting them.

hdoj 1799 循环多少次?

循环多少次? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3322    Accepted Submission(s): 1235 Problem Description 我们知道,在编程中,我们时常需要考虑到时间复杂度,特别是对于循环的部分.例如,如果代码中出现for(i=1;i<=n;i++) OP ;那么做了n次OP运算,如果代

[HDOJ]_2005_第几天?

题目: Problem Description 给定一个日期,输出这个日期是该年的第几天. Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的. Output 对于每组输入数据,输出一行,表示该日期是该年的第几天. Sample Input 1985/1/20 2006/3/12 Sample Output 20 71 Author lcy Source C语言程序设计练习(一) Recomme

HDOJ 4582 - DFS spanning tree - DFS树,贪心

题目大意: 给定一个N个点.M条边的无向图Graph,以及从点1开始进行DFS形成的树Tree,定义"T-Simple Circle"为Graph中的环,要求其中只含一条不属于Tree的边. 将Graph中的一些边进行染色,使得其中每个T-simple Circle都至少包含一条被染色的边,求最少需要染色的边数. N≤2e3,M≤2e4 本题关键的一点在于Tree是一棵DFS生成树,这样Tree以外的边只可能将某个点与它在Tree中的祖先相连(用反证法可以证明,只有这样才能维持DFS树

EF6与mvc5系列(1)开始

本系列教程是微软asp.net网站上的教程翻译,原文地址:http://www.asp.net/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application . 我们将用EF6和mvc5技术完成一个应用程序Contoso University.这是一个虚拟的项目.里面包含学生管理,成绩管理,课

hdoj 5038 Grade【众数】

题目:hdoj 5038 Grade 题意:给出一组数,求众数,按升序输出 分析:只考众数的概念,但是一直没有搞清楚 众数:一组数中出现次数最多的数,假如所有数据的出现次数都一样,那么这组数据没有众数.(注意:数组中只有一个数的话众数就是它本身) AC 代码: #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #inc

HDOJ 题目2586 How far away ?(LCA)

How far away ? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7090    Accepted Submission(s): 2578 Problem Description There are n houses in the village and some bidirectional roads connecting

HDOJ 5038 Grade

Grade Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Submission(s): 194    Accepted Submission(s): 105 Problem Description Ted is a employee of Always Cook Mushroom (ACM). His boss Matt gives him a pack of