topic:
analysis:
Is used repeatedly sort () to sort, but here comprising an output at the same rank, may be provided to a v maxx and output the same ranking, the following specific operation has been given the code
Code:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int MAXN = 30005;
int n,k;
struct node
{
long long id;
int score;
int loRank;
int ind;
}no[MAXN];
bool Cmp(const node &n1,const node &n2)
{
return n1.score > n2.score;
}
bool Cmp1(const node &n1,const node &n2)
{
if(n1.score != n2.score)
return n1.score > n2.score;
else
return n1.id < n2.id;
}
int main()
{
scanf("%d",&n);
int index = 1;
for(int i=1;i<=n;++i)
{
scanf("%d",&k);
for(int j=index;j<k+index;++j)
{
scanf("%lld %d",&no[j].id,&no[j].score);
no[j].ind = i;
}
sort(no+index,no+index+k,Cmp);
int v=0,maxx=INF; //对含有相同名次的同学所做的处理
for(int j=1;j<=k;++j)
if(no[j+index-1].score == maxx)
no[j+index-1].loRank = v;
else
{
maxx = no[j+index-1].score;
v = j;
no[j+index-1].loRank = v;
}
index = k+index;
}
sort(no+1,no+index,Cmp1);
int v=0,maxx=INF;
printf("%d\n",index-1);
for(int i=1;i<index;++i)
{
if(maxx != no[i].score)
{
v = i;
maxx = no[i].score;
}
printf("%013lld %d %d %d\n",no[i].id,v,no[i].ind,no[i].loRank);
}
return 0;
}