fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <math.h>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. bool ij(vector<int> i, vector<int> j) {
  8. int a = i.size();
  9. int b = j.size();
  10. int c = max(a,b)-min(a,b);
  11. double ans1 = 1.0;
  12. double ans2 = 1.0;
  13. if(a>b) {
  14. for(int it = 1; it <= c+1; it++) {
  15. ans1 = pow((double)i[a-it], ans1);
  16. }
  17. ans2 = (double)j[b-1];
  18. } else if(b>a) {
  19. for(int it = 1; it <= c+1; it++) {
  20. ans2 = pow((double)j[b-it], ans2);
  21. }
  22. ans1 = (double)i[a-1];
  23. } else {
  24. ans1 = (double)i[a-1];
  25. ans2 = (double)j[b-1];
  26. }
  27. c = min(a,b);
  28. double da, db;
  29. for(int it = 2; it <= c; it++) {
  30. da = log2((double)i[c-it])*ans1;
  31. db = log2((double)j[c-it])*ans2;
  32. if(da>db) {
  33. ans1=pow(2,da-db);
  34. ans2=1.0;
  35. } else if(da<db) {
  36. ans2=pow(2,db-da);
  37. ans1=1.0;
  38. }
  39. }
  40. return ans1<ans2;
  41. }
  42.  
  43. int main()
  44. {
  45. int n;
  46. cin >> n;
  47. int k, t;
  48. vector<int> vt(10);
  49. bool bo;
  50. vector<vector<int> > vc(n,vt);
  51. for(int i = 0; i < n; i++) {
  52. cin >> k;
  53. bo = true;
  54. k++;
  55. vc[i].reserve(k);
  56. for(int j = 0;j < k; j++) {
  57. cin >> t;
  58. if(t==1) {
  59. bo = false;
  60. if(j==0) {
  61. vc[i].push_back(1);
  62. }
  63. } else if(bo) {
  64. vc[i].push_back(t);
  65. }
  66. }
  67. }
  68. vector<vector<int> > hu = vc;
  69. sort(vc.begin(), vc.end(), ij);
  70. for(int i = 0; i < n; i++) {
  71. for(int j = 0; j < n; j++) {
  72. if(vc[i]==hu[j]) {
  73. cout << j+1 << " ";
  74. break;
  75. }
  76. }
  77. }
  78. cin >> n;
  79. return 0;
  80. }
  81.  
Success #stdin #stdout 0s 16072KB
stdin
10
4 2 2 2 2 2
1 2 2
1 3 2
1 2 3
3 2 2 2 2
2 2 2 2
1 3 3
3 3 3 3 3
2 4 3 3
2 2 3 4
stdout
2 4 3 6 7 5 9 10 1 8