Quailty and CCPC(HDU-6666)

Problem Description

Considering the overall difficulty of other problems, we invite Quailty to propose an easy problem for this contest.

Quailty accidentally won both gold medal and silver medal in 2017 CCPC final. The reason is explained as follows. According to the official rule, the number of gold medals was 10\% of the number of participating teams, rounded to the nearest integer. This is ambiguous when the fractional part of the result is exactly 0.5. There were 115 participating teams, and the rank of Quailty's team was 12. The organizer originally decided to round down the number, so there were only 11 gold medals, and Quailty's team could only win the silver medal. Many people defended him against the organizer, saying that his team deserved a gold medal. Later, the organizer changed to round up the number, and Quailty's team finally won a gold medal.

Now, give you the scoreboard of a contest and the proportion of gold medal teams, could you determine whether there exists a team, such that they would win a gold medal were the number of gold medals rounded up when the fractional part is exactly 0.5, and silver medal if rounded down?

A team ranks before another if they solved more problems or both teams solved an equal number of problems but they had less penalty time.

(Disclaimer: the background is fictitious and the problem is prepared by Nanjing University ICPC Training Team, not Quailty.)

Input

The first line of input consists of a single integer T (1≤T≤120), denoting the number of test cases.

Each test case starts with a line of two integers n (1≤n≤105), denoting the number of participating teams, and d (0≤d≤9), denoting that the proportion of gold medal teams is 10d%. For the next n lines, each containing a string s and two integers p,t (0≤p,t≤109), denoting the name of the team, the number of problems solved and the penalty time of the team, respectively. The name of the each team contains at least 1 and at most 10 latin letters. The names are case sensitive. No two teams have the same name. No two teams have the same penalty time. The sum of n over all test cases does not exceed 106.

Output

For each test case, print the team name if there exists such team, or print Quailty is very great otherwise. It can be proved that there is at most one such team.

Sample Input

2
5 1
Ace 1000 0
Luffy 999 1
Sabo 998 2
Roronoa 997 3
Sanji 996 4
2 3
You 0 0
I 10 1

Sample Output

Ace
Quailty is very great

题意:t 组数据,每组给出 n 个团队解决的问题数量与罚时,再给出一个整数 d,前 d*10% 代表金牌数量,假设有 115 个队伍参赛,10% 的队伍获得金牌,那么有 11.5 只队伍是金牌,如果四舍五入到 12,第 12 名就会获得金牌,如果舍去到 11,第 11 名就会得到金牌,询问是否存在一只队伍,其既有可能得到金牌也有可能得到银牌,如果有,输出队伍名称,如果没有,输出 Quailty is very great

思路:耿直的签到题,用一个结构体来存队伍的信息,然后写一个比较规则,利用 sort 函数排序后判断即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;}
LL quickMultPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;}
LL quickPowMod(LL a,LL b,LL mod){ LL res=1; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1; } return res; }
LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-10;
const int MOD = 1000000000+7;
const int N = 100000+5;
const int dx[] = {0,0,-1,1,1,-1,1,1};
const int dy[] = {1,-1,0,0,-1,1,-1,1};
using namespace std;

struct Team {
    char name[15];
    int num;
    int time;
    bool operator<(const Team &rhs) const {
        if (num == rhs.num)
            return time<rhs.time;
        return num>rhs.num;
    }
} team[N];

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        int n, d;
        scanf("%d%d", &n, &d);
        for (int i = 1; i <= n; i++)
            scanf("%s%d%d", team[i].name, &team[i].num, &team[i].time);

        sort(team + 1, team + 1 + n);
        double ans = n * (d * 10) / 100.0;
        int decimal = ((int)(ans * 10)) % 10; //小数部分
        if (decimal == 5) {
            int i = ceil(ans);
            printf("%s\n", team[i].name);
        } else
            cout << "Quailty is very great" << endl;
    }
    return 0;
}
发布了1871 篇原创文章 · 获赞 702 · 访问量 194万+

猜你喜欢

转载自blog.csdn.net/u011815404/article/details/102535768