fork download
  1. #include <bits/stdc++.h>
  2. #define _ ios_base::sync_with_stdio(0);
  3.  
  4. using namespace std;
  5. struct equipe{
  6. int pontuacao,sm,sr,id;
  7. float razao;
  8. };
  9. bool cmp(equipe a , equipe b){
  10. if (a.pontuacao!=b.pontuacao)
  11. return a.pontuacao>b.pontuacao;
  12. if(a.razao!=b.razao)
  13. return a.razao>b.razao;
  14. if(a.sm!=b.sm)
  15. return a.sm>b.sm;
  16. return a.id<b.id;
  17. }
  18. equipe times[101];
  19. int n,x,y,z,w,caso;
  20.  
  21. int main(){_
  22. cin >>n;
  23. while(n!=0){
  24. if(caso!=0)
  25. cout<<endl;
  26. for (int i=0;i<(n*(n-1)/2);i++){
  27. cin >>x>>y>>z>>w;
  28. times[x].id=x;
  29. times[x].sm+=y;
  30. times[x].sr+=w;
  31. times[x].razao=(times[x].sr!=0)?(times[x].sm/(float)times[x].sr):times[x].sm;
  32. times[z].id=z;
  33. times[z].sm+=w;
  34. times[z].sr+=y;
  35. times[z].razao=(times[z].sr!=0)?(times[z].sm/(float)times[z].sr):times[z].sm ;
  36. if (y>w){
  37. times[x].pontuacao+=2;
  38. times[z].pontuacao++;
  39. }else{
  40. times[z].pontuacao+=2;
  41. times[x].pontuacao++;
  42. }
  43. }
  44. sort(times,times+n+1,cmp);
  45. cout <<"Instancia "<<++caso<<endl;
  46. int i;
  47. for(i=0;i<n-1;i++){
  48. cout <<times[i].id<<" ";
  49. }
  50. cout<<times[i].id<<endl;
  51.  
  52.  
  53. cin >>n;
  54. for( i=0;i<101;i++){
  55. times[i].id=0;
  56. times[i].sm=0;
  57. times[i].sr=0;
  58. times[i].razao=0;
  59. times[i].pontuacao=0;
  60. }
  61. }
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 4180KB
stdin
5
1 102 2 62
1 128 3 127
1 144 4 80
1 102 5 101
2 62 3 61
2 100 4 80
2 88 5 82
3 79 4 90
3 87 5 100
4 110 5 99
0
stdout
Instancia 1
1 2 4 5 3