1025. PAT Ranking

#include<iostream>
#include<algorithm>
using namespace std;
const int N=30003;
struct node{
  unsigned long long id;
  int place,goal,lrank,trank;
  node():lrank(1),trank(1){}
};
node man[N];
int  main(){
  int place,total(0);
  cin>>place;
  for(int i=1; i<=place; ++i){
    int cnt; cin>>cnt;
    for(int j=0; j<cnt; ++j){
      auto &x=man[total+j];
      cin>>x.id>>x.goal;
      x.place=i; }//for
    sort(man+total,man+total+cnt,[](const node&x,const node&y){\
	return x.goal!=y.goal?x.goal>y.goal:x.id<y.id;});
    for(int j=total+1;j<total+cnt;++j)
      man[j].lrank=(man[j-1].goal==man[j].goal?man[j-1].lrank:j-total+1);
    total+=cnt;
  }//for
  sort(man,man+total,[](const node&x,const node&y){	\
      return x.goal!=y.goal?x.goal>y.goal:x.id<y.id;});
  for(int i=1;i<total;++i)
    man[i].trank=(man[i-1].goal==man[i].goal?man[i-1].trank:i+1);
  cout<<total<<endl;
  for(int i=0;i<total;++i)
    printf("%013llu %d %d %d\n",man[i].id,man[i].trank,man[i].place,man[i].lrank);
  
}



你可能感兴趣的:(1025. PAT Ranking)