1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| #include<iostream> #include<algorithm> #include<vector> using namespace std; struct country { int number; int prizes[3]; int rank; }; int N, M;
vector<country> countries1, countries2, countries3, countries4; bool cmp1(country c1, country c2); bool cmp2(country c1, country c2); bool cmp3(country c1, country c2); bool cmp4(country c1, country c2); void generateRank(int condition); int findRank(int condition, int number); int main() { scanf("%d %d", &N, &M); for(int i = 0; i < N; i++) { country tempCountry; scanf("%d %d %d", &tempCountry.prizes[0], &tempCountry.prizes[1], &tempCountry.prizes[2]); tempCountry.number = i; countries1.push_back(tempCountry); countries2.push_back(tempCountry); countries3.push_back(tempCountry); countries4.push_back(tempCountry); } sort(countries1.begin(), countries1.end(), cmp1); sort(countries2.begin(), countries2.end(), cmp2); sort(countries3.begin(), countries3.end(), cmp3); sort(countries4.begin(), countries4.end(), cmp4); for(int i = 0; i < 4; i++){ generateRank(i); } for(int i = 0; i < M; i++) { int query; scanf("%d", &query); int ranks[4]; for(int j = 0; j < 4; j++) { ranks[j] = findRank(j + 1, query); } int minIndex = 0; for(int j = 1; j < 4; j++) { if(ranks[j] < ranks[minIndex]) { minIndex = j; } } printf("%d:%d", ranks[minIndex], minIndex + 1); if(i == M - 1) { printf("\n"); } else { printf(" "); } } return 0; } bool cmp1(country c1, country c2) { return c1.prizes[0] > c2.prizes[0]; } bool cmp2(country c1, country c2) { return c1.prizes[1] > c2.prizes[1]; } bool cmp3(country c1, country c2) { return c1.prizes[0] * 1.0 / c1.prizes[2] > c2.prizes[0] * 1.0 / c2.prizes[2]; } bool cmp4(country c1, country c2) { return c1.prizes[1] * 1.0 / c1.prizes[2] > c2.prizes[1] * 1.0 / c2.prizes[2]; } void generateRank(int condition) { if(condition == 0) { for(int i = 0; i < countries1.size(); i++) { if(i > 0 && countries1[i].prizes[0] == countries1[i - 1].prizes[0]) { countries1[i].rank = countries1[i - 1].rank; } else { countries1[i].rank = i; } } } else if(condition == 1) { for(int i = 0; i < countries2.size(); i++) { if(i > 0 && countries2[i].prizes[1] == countries2[i - 1].prizes[1]) { countries2[i].rank = countries2[i - 1].rank; } else { countries2[i].rank = i; } } } else if(condition == 2) { for(int i = 0; i < countries3.size(); i++) { if(i > 0 && countries3[i].prizes[0] * 1.0 / countries3[i].prizes[2] == countries3[i - 1].prizes[0] * 1.0 / countries3[i - 1].prizes[2]) { countries3[i].rank = countries3[i - 1].rank; } else { countries3[i].rank = i; } } } else { for(int i = 0; i < countries4.size(); i++) { if(i > 0 && countries4[i].prizes[0] * 1.0 / countries4[i].prizes[2] == countries4[i - 1].prizes[0] * 1.0 / countries4[i - 1].prizes[2]) { countries4[i].rank = countries4[i - 1].rank; } else { countries4[i].rank = i; } } } } int findRank(int condition, int number) { if(condition == 1) { for(int i = 0; i < countries1.size(); i++) { if(number == countries1[i].number) { return countries1[i].rank + 1; } } } else if(condition == 2) { for(int i = 0; i < countries2.size(); i++) { if(number == countries2[i].number) { return countries2[i].rank + 1; } } } else if(condition == 3) { for(int i = 0; i < countries3.size(); i++) { if(number == countries3[i].number) { return countries3[i].rank + 1; } } } else { for(int i = 0; i < countries4.size(); i++) { if(number == countries4[i].number) { return countries4[i].rank + 1; } } } }
|