天天看點

http://pat.zju.edu.cn/contests/pat-practise/1025

1025. PAT Ranking (25) 時間限制 200 ms

記憶體限制 32000 kB

代碼長度限制 16000 B

判題程式 Standard 作者 CHEN, Yue

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (<=100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (<=300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank

The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
      

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4
      

尼瑪,多浪費時間啊,本來想偷懶對不同場進行排序,竟然逾時。偷懶變辛苦。。。 [cpp]  view plain copy

  1. #include <iostream>  
  2. #include <string>  
  3. #include <algorithm>  
  4. #include <memory.h>  
  5. #include <cstdio>  
  6. #include <cstdlib>  
  7. #include <vector>  
  8. using namespace std;  
  9. #define MAX 0Xfffffff  
  10. int n;  
  11. char names[30003][14];  
  12. struct Node{  
  13.     int th;  
  14.     int local;  
  15.     int final;  
  16.     int iid;  
  17.     int grade;  
  18.     bool operator<(const Node& node)const{  
  19.         if(grade!=node.grade)  
  20.             return grade>node.grade;  
  21.         return strcmp(names[iid], names[node.iid])<0;  
  22.     }  
  23. };  
  24. Node nodes[30003];  
  25. int main(){  
  26.     //freopen("in.txt", "r", stdin);  
  27.     cin>>n;  
  28.     int m;  
  29.     int cnt = 0;  
  30.     for(int i=1;i<=n;++i){  
  31.         cin>>m;  
  32.         for(int j=0;j<m;++j){  
  33.             scanf(" %s %d", names[cnt], &nodes[cnt].grade);  
  34.             nodes[cnt].iid = cnt;  
  35.             nodes[cnt++].th = i;  
  36.         }  
  37.     }  
  38.     sort(nodes, nodes+cnt);  
  39.     int pre[101];  
  40.     int th[101];  
  41.     for(int i=0;i<101;i++)  
  42.         pre[i] = -1;  
  43.     int pv;  
  44.     for(int i=0;i<cnt;++i){    
  45.         if(i==0){  
  46.             pv = i;  
  47.             nodes[i].final = 1;  
  48.         }  
  49.         else{  
  50.             if(nodes[i].grade==nodes[pv].grade)  
  51.                 nodes[i].final = nodes[pv].final;  
  52.             else{  
  53.                 nodes[i].final = i+1;  
  54.                 pv = i;  
  55.             }  
  56.         }  
  57.         if(pre[nodes[i].th]==-1){  
  58.             pre[nodes[i].th] = i;  
  59.             nodes[i].local = 1;  
  60.             th[nodes[i].th] = 2;  
  61.         }else{  
  62.             if(nodes[pre[nodes[i].th]].grade == nodes[i].grade){  
  63.                 nodes[i].local = nodes[pre[nodes[i].th]].local;  
  64.             }else{  
  65.                 nodes[i].local = th[nodes[i].th];     
  66.                 pre[nodes[i].th] = i;  
  67.             }  
  68.             th[nodes[i].th]++;  
  69.         }  
  70.     }  
  71.     cout<<cnt<<endl;  
  72.     for(int i=0;i<cnt;++i){  
  73.         printf("%s %d %d %d\n", names[nodes[i].iid], nodes[i].final, nodes[i].th, nodes[i].local);  
  74.     }  
  75.    //fclose(stdin);  
  76. }     

繼續閱讀