#include <iostream>
#include <string>
using namespace std;
int plan[1000000][4] = {};
int main() {
int count = 4;
cin >> count;
// int plan[4][4] = { {1, 5, 2, 0}, {2, 3, 0, 0}, {2, 3, 6, 0}, {1, 7, 4, 0} };
for (int counter = 0; counter < count; counter++) {
cin >> plan[counter][0];
cin >> plan[counter][1];
cin >> plan[counter][2];
plan[counter][3] = 0;
}
int collision = 0;
int groupNumber;
int collisionCounter;
int supplyCounter[2] = { 0, 0 };
int supplyToRemove = 0;
for (int group = 0; group < count; group++) {
if (plan[group][3] > 0)
continue;
groupNumber = plan[group][1] - plan[group][2];
supplyCounter[0] = 0;
supplyCounter[1] = 0;
for (int iteration = group; iteration < count; iteration++)
{
if (plan[iteration][1] - plan[iteration][2] == groupNumber) {
supplyCounter[plan[iteration][0] - 1]++;
plan[iteration][3] = 1;
}
}
supplyToRemove += min(supplyCounter[0], supplyCounter[1]);
//cout << to_string(supplyCounter[0]) + " " + to_string(supplyCounter[1]) + "\n";
}
cout << to_string(supplyToRemove);
//for (int supply = 0; supply < count; supply++)
// cout << to_string(supply) + " " + to_string(plan[supply][3]) + "\n";
return 0;
}
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 | #include <iostream> #include <string> using namespace std; int plan[1000000][4] = {}; int main() { int count = 4; cin >> count; // int plan[4][4] = { {1, 5, 2, 0}, {2, 3, 0, 0}, {2, 3, 6, 0}, {1, 7, 4, 0} }; for (int counter = 0; counter < count; counter++) { cin >> plan[counter][0]; cin >> plan[counter][1]; cin >> plan[counter][2]; plan[counter][3] = 0; } int collision = 0; int groupNumber; int collisionCounter; int supplyCounter[2] = { 0, 0 }; int supplyToRemove = 0; for (int group = 0; group < count; group++) { if (plan[group][3] > 0) continue; groupNumber = plan[group][1] - plan[group][2]; supplyCounter[0] = 0; supplyCounter[1] = 0; for (int iteration = group; iteration < count; iteration++) { if (plan[iteration][1] - plan[iteration][2] == groupNumber) { supplyCounter[plan[iteration][0] - 1]++; plan[iteration][3] = 1; } } supplyToRemove += min(supplyCounter[0], supplyCounter[1]); //cout << to_string(supplyCounter[0]) + " " + to_string(supplyCounter[1]) + "\n"; } cout << to_string(supplyToRemove); //for (int supply = 0; supply < count; supply++) // cout << to_string(supply) + " " + to_string(plan[supply][3]) + "\n"; return 0; } |
English