题目链接:https://www.patest.cn/contests/pat-a-practise/1025
吐槽:我用数组做了一个版本,有两个测试点过不去,现在又用vector做了一个几乎一模一样的就给过了,有毒!
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
struct Node{
long long int id;
int score,local,rankl;
};
bool cmp(Node a,Node b){
if(a.score != b.score)
return a.score >b.score;
else return a.id < b.id;
}
int main(){
int n,k,num=0;
scanf("%d",&n);
vector<Node> vt;
for(int i=1;i <= n;i++){
scanf("%d",&k);
vector<Node> v(k);
for(int j=0;j<k;j++){
scanf("%lld %d",&v[j].id,&v[j].score);
v[j].local = i;
}
sort(v.begin(),v.end(),cmp);
v[0].rankl=1;
vt.push_back(v[0]);
for(int j=1;j < k;j++){
if(v[j-1].score==v[j].score){
v[j].rankl =v[j-1].rankl;
}else{
v[j].rankl= j+1;
}
vt.push_back(v[j]);
}
}
sort(vt.begin(),vt.end(),cmp);
printf("%d\n",vt.size());
int r = 1;
for(int j=0;j < vt.size();j++){
if(j>0&&vt[j-1].score!=vt[j].score){
r = j + 1;
}
printf("%013lld %d %d %d\n",vt[j].id,r,vt[j].local,vt[j].rankl);
}
return 0;
}