#include <stdio.h>
#include <stdbool.h>
#include <string>
#include <algorithm>
#include <map>
using namespace std;
bool bPause = !true;
int main()
{
int n;
scanf("%d\n", &n);
map<int, int> a_map;
map<int, int> b_map;
map<int, int> ids;
int type, pos, time;
for (int i = 0; i < n; i++)
{
scanf("%d %d %d\n", &type, &pos, &time);
const int id = pos - time;
if (type == 1)
{
int v = (a_map.find(id) != a_map.end() ? a_map.find(id)->second : 0) + 1;
a_map[id] = v;
ids[id] = 1;
}
else
{
int v = (b_map.find(id) != b_map.end() ? b_map.find(id)->second : 0) + 1;
b_map[id] = v;
ids[id] = 1;
}
}
int res = 0;
for (std::map<int, int>::iterator it = ids.begin(); it != ids.end(); ++it)
{
int i = it->first;
if (a_map[i] > 0 && b_map[i] > 0)
{
res += (a_map[i] < b_map[i] ? a_map[i] : b_map[i]);
}
}
printf("%d\n", res);
if (bPause)
while (true);
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 56 57 | #include <stdio.h> #include <stdbool.h> #include <string> #include <algorithm> #include <map> using namespace std; bool bPause = !true; int main() { int n; scanf("%d\n", &n); map<int, int> a_map; map<int, int> b_map; map<int, int> ids; int type, pos, time; for (int i = 0; i < n; i++) { scanf("%d %d %d\n", &type, &pos, &time); const int id = pos - time; if (type == 1) { int v = (a_map.find(id) != a_map.end() ? a_map.find(id)->second : 0) + 1; a_map[id] = v; ids[id] = 1; } else { int v = (b_map.find(id) != b_map.end() ? b_map.find(id)->second : 0) + 1; b_map[id] = v; ids[id] = 1; } } int res = 0; for (std::map<int, int>::iterator it = ids.begin(); it != ids.end(); ++it) { int i = it->first; if (a_map[i] > 0 && b_map[i] > 0) { res += (a_map[i] < b_map[i] ? a_map[i] : b_map[i]); } } printf("%d\n", res); if (bPause) while (true); return 0; } |
English