(这是一道我八场以来唯一一次写到的水题了,但它还是让我贡献了3发 TLE qwq,所以它虽然水,我也得把它记录下来,免得下次再因此而罚时)
题目链接:传送门儿
题意:根据传统赛制,每场比赛,金牌数为总参赛人数的百分之10*d,由于总人数*10*d/100 可能不是一个整数,一般采取四舍五入的方式来确定最终人数,但当碰到0.5时,是向上取整还是向下取整却是模糊不清的,故,问最终排名榜上是否存在某个队,当向上取整时该队拿金牌,向下取整时拿银牌?(有则输出该队队名,没有则输出Quailty is very great.)题目保证不会有同名或者并列的队伍。当题目做得更多,时间用得越少,队伍更靠前。
思路:就排个序,然后判断n*d%10是否等于5,若等于则存在,不等于则不存在。
(超时错就错在string上,详看代码)
//正确代码
#include <bits/stdc++.h>
using namespace std;
struct team//在结构体内部重载<运算符
{
string name;//用string来存队名
int p,t;
bool operator < (const team &other) const
{
if(p>other.p)
return true;
else if(p==other.p)
{
if(t<other.t)
return true;
}
return false;
}
};
team a[100005];
int main()
{
//freopen("in.txt","r",stdin);
std::ios::sync_with_stdio(false);
int t;
cin>>t;
while(t--)
{
int n,d;
cin>>n>>d;
for(int i=0; i<n; i++)
{
cin>>a[i].name>>a[i].p>>a[i].t;
}
sort(a,a+n);
if(n*d%10==5)
{
int tt=n*d/10;
cout<<a[tt].name<<endl;
}
else
cout<<"Quailty is very great"<<endl;
}
return 0;
}
//第二份正确代码
#include <bits/stdc++.h>
using namespace std;
struct team
{
char name[15];//用字符数组存队名
int p,t;
};
team a[100005];
bool cmp(team x,team y)//在外面重写cmp函数,此时如果继续用string就会超时了
{
if(x.p>y.p)
return true;
else if(x.p==y.p)
{
return x.t<y.t;
}
return false;
}
int main()
{
//freopen("in.txt","r",stdin);
int t;
scanf("%d",&t);
while(t--)
{
int n,d;
scanf("%d%d",&n,&d);
for(int i=0; i<n; i++)
scanf("%s%d%d",a[i].name,&a[i].p,&a[i].t);
sort(a,a+n,cmp);
// for(int i=0;i<n;i++)
// cout<<a[i].name<<endl;
if(n*d%10==5)
{
int tt=n*d/10;
printf("%s\n",a[tt].name);
}
else
printf("Quailty is very great\n");
}
return 0;
}