#include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n; scanf("%d", &n); int *lcars = (int*)malloc(n * sizeof(int)); memset(lcars, 0, n * sizeof(int)); int *bcars = (int*)malloc(n * sizeof(int)); memset(bcars, 0, n * sizeof(int)); int tmp, tmpo[2]; int lcount = 0, bcount = 0; for (int i = 0; i < n; i++) { scanf("%d", &tmp); if (tmp-1) { scanf("%d %d", &tmpo[0], &tmpo[1]); lcars[lcount] = tmpo[0] - tmpo[1]; lcount++; } else{ scanf("%d %d", &tmpo[0], &tmpo[1]); bcars[bcount] = tmpo[0] - tmpo[1]; bcount++; } } int arr_l = 2000000*2; int *barr = (int*)malloc(arr_l * sizeof(int)); memset(barr, 0, arr_l * sizeof(int)); int *bmap = &barr[arr_l/2]; for (int i = 0; i < bcount; i++) { bmap[bcars[i]]++; } int *larr = (int*)malloc(arr_l * sizeof(int)); memset(larr, 0, arr_l * sizeof(int)); int *lmap = &larr[arr_l/2]; for (int i = 0; i < lcount; i++) { lmap[lcars[i]]++; } int wynik = 0; int *done = (int*)malloc(lcount * sizeof(int)); memset(done, 0, lcount * sizeof(int)); int done_l = 0; bool isNew; for (int i = 0; i < lcount; i++) { isNew = 1; for (int j = 0; j < done_l; j++) { if (lcars[i] == done[j]) isNew = 0; } if (isNew) { // printf("%d %d %d\n", lcars[i], bmap[lcars[i]], lmap[lcars[i]]); wynik += bmap[lcars[i]] > lmap[lcars[i]] ? lmap[lcars[i]] : bmap[lcars[i]]; done[done_l] = lcars[i]; done_l++; } } printf("%d\n", wynik); 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 58 59 60 | #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { int n; scanf("%d", &n); int *lcars = (int*)malloc(n * sizeof(int)); memset(lcars, 0, n * sizeof(int)); int *bcars = (int*)malloc(n * sizeof(int)); memset(bcars, 0, n * sizeof(int)); int tmp, tmpo[2]; int lcount = 0, bcount = 0; for (int i = 0; i < n; i++) { scanf("%d", &tmp); if (tmp-1) { scanf("%d %d", &tmpo[0], &tmpo[1]); lcars[lcount] = tmpo[0] - tmpo[1]; lcount++; } else{ scanf("%d %d", &tmpo[0], &tmpo[1]); bcars[bcount] = tmpo[0] - tmpo[1]; bcount++; } } int arr_l = 2000000*2; int *barr = (int*)malloc(arr_l * sizeof(int)); memset(barr, 0, arr_l * sizeof(int)); int *bmap = &barr[arr_l/2]; for (int i = 0; i < bcount; i++) { bmap[bcars[i]]++; } int *larr = (int*)malloc(arr_l * sizeof(int)); memset(larr, 0, arr_l * sizeof(int)); int *lmap = &larr[arr_l/2]; for (int i = 0; i < lcount; i++) { lmap[lcars[i]]++; } int wynik = 0; int *done = (int*)malloc(lcount * sizeof(int)); memset(done, 0, lcount * sizeof(int)); int done_l = 0; bool isNew; for (int i = 0; i < lcount; i++) { isNew = 1; for (int j = 0; j < done_l; j++) { if (lcars[i] == done[j]) isNew = 0; } if (isNew) { // printf("%d %d %d\n", lcars[i], bmap[lcars[i]], lmap[lcars[i]]); wynik += bmap[lcars[i]] > lmap[lcars[i]] ? lmap[lcars[i]] : bmap[lcars[i]]; done[done_l] = lcars[i]; done_l++; } } printf("%d\n", wynik); return 0; } |