#include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; int main() { int n; cin >> n; string str; int maxA = 0; int maxU = 0; int total = 0; int odwolania = 0; int** who = (int**)malloc(n * sizeof(int*)); int** rows = (int**)malloc(n * sizeof(int*)); for (int i = 0; i < n; i++) { who[i] = (int*)malloc(n * sizeof(int)); rows[i] = (int*)malloc(5 * sizeof(int)); int r, w, t; string row; getline(cin >> ws, row); istringstream f(row); getline(f, str, ' '); r = std::stoi(str); rows[i][0] = r; getline(f, str, ' '); w = std::stoi(str); rows[i][1] = std::stoi(str); getline(f, str, ' '); rows[i][2] = std::stoi(str); rows[i][3] = 0; rows[i][4] = 0; if (r == 1) maxA = max(w, maxA); else maxU = max(w, maxU); } for (int i = 0; i < n; i++) { int r = rows[i][0]; int w = rows[i][1]; int t = rows[i][2]; for (int j = i + 1; j < n; j++) { int r2 = rows[j][0]; if (r2 == r) continue; int w2 = rows[j][1]; int t2 = rows[j][2]; if (t + w2 == t2 + w) { rows[i][3]++; rows[j][3]++; total++; who[i][rows[i][4]] = j; who[j][rows[j][4]] = i; rows[i][4]++; rows[j][4]++; } } } while(total > 0) { int index = -1; int max = -1; for (int i = 0; i < n; i++) { if(rows[i][3] > max) { max = rows[i][3]; index = i; } } total -= max; rows[index][3] = 0; for (int j = 0; j < rows[index][4]; j++) { int whooo = who[index][j]; if (whooo < 0) continue; rows[whooo][3]--; } odwolania++; } cout << odwolania << endl; }
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 | #include <iostream> #include <string> #include <fstream> #include <sstream> using namespace std; int main() { int n; cin >> n; string str; int maxA = 0; int maxU = 0; int total = 0; int odwolania = 0; int** who = (int**)malloc(n * sizeof(int*)); int** rows = (int**)malloc(n * sizeof(int*)); for (int i = 0; i < n; i++) { who[i] = (int*)malloc(n * sizeof(int)); rows[i] = (int*)malloc(5 * sizeof(int)); int r, w, t; string row; getline(cin >> ws, row); istringstream f(row); getline(f, str, ' '); r = std::stoi(str); rows[i][0] = r; getline(f, str, ' '); w = std::stoi(str); rows[i][1] = std::stoi(str); getline(f, str, ' '); rows[i][2] = std::stoi(str); rows[i][3] = 0; rows[i][4] = 0; if (r == 1) maxA = max(w, maxA); else maxU = max(w, maxU); } for (int i = 0; i < n; i++) { int r = rows[i][0]; int w = rows[i][1]; int t = rows[i][2]; for (int j = i + 1; j < n; j++) { int r2 = rows[j][0]; if (r2 == r) continue; int w2 = rows[j][1]; int t2 = rows[j][2]; if (t + w2 == t2 + w) { rows[i][3]++; rows[j][3]++; total++; who[i][rows[i][4]] = j; who[j][rows[j][4]] = i; rows[i][4]++; rows[j][4]++; } } } while(total > 0) { int index = -1; int max = -1; for (int i = 0; i < n; i++) { if(rows[i][3] > max) { max = rows[i][3]; index = i; } } total -= max; rows[index][3] = 0; for (int j = 0; j < rows[index][4]; j++) { int whooo = who[index][j]; if (whooo < 0) continue; rows[whooo][3]--; } odwolania++; } cout << odwolania << endl; } |