RC-u1 亚运奖牌榜 - 2023 睿抗机器人开发者大赛CAIP-编程技能赛-本科组(省赛) (pintia.cn) 我刚开始这样写有一个测试点过不去:
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
const int N=1010;
struct P
{
int x,y,z,f;
}q[N];
bool cmp(P a,P b)
{
if(a.x==b.x)
{
if(a.y==b.y)
{
return a.z>b.z;
}
else return a.y>b.y;
}
return a.x>b.x;
}
signed main()
{
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n;
for(int i=0;i<n;i++)
{
int a,b;cin>>a>>b;
q[a].f=a;
if(b==1)
{
q[a].x++;
}
else if(b==2)
{
q[a].y++;
}
else if(b==3)
{
q[a].z++;
}
}
cout<<q[0].x<<" "<<q[0].y<<" "<<q[0].z<<endl;
cout<<q[1].x<<" "<<q[1].y<<" "<<q[1].z<<endl;
sort(q,q+n,cmp);
if(q[0].f==0)
{
cout<<"The first win!\n";
}
else
{
cout<<"The second win!\n";
}
return 0;
}
把
sort(q,q+n,cmp)改为sort(q,q+2,cmp)就可以过了:
原因是(q+n)全排的话后面的元素的值都是0,就会排到前面去影响结果.因为只有两个国家,所以我们只排两个国家就可以了.