#include <stdio.h> #include <stdlib.h> int my_compare(const void* j,const void* d) { if (*((int*)j+1) > *((int*)d+1)) { return 1;} return -1; } int main() { int liczba_testow; scanf("%d",&liczba_testow); int vector[4]; for (int a=0;a < liczba_testow;a++) { int ls; int sz; scanf("%d %d",&ls,&sz); int* tablica = (int*) malloc (sizeof(int)*3*ls); int* tablica2 = (int*) malloc (sizeof(int)*3*ls); for (int b=0;b < ls;b++) { scanf("%d %d %d %d",vector,vector+1,vector+2,vector+3); tablica[3*b] = b; tablica[3*b+1] = vector[0]; tablica[3*b+2] = abs(vector[1]-vector[3]); } for (int b=0;b < ls;b++) { scanf("%d %d %d %d",vector,vector+1,vector+2,vector+3); tablica2[3*b] = b; tablica2[3*b+1] = vector[0]; tablica2[3*b+2] = abs(vector[1]-vector[3]); } qsort((void*)tablica,ls,sizeof(int)*3,my_compare); qsort((void*)tablica2,ls,sizeof(int)*3,my_compare); for (int zz=0;zz < ls;zz += 3) { int element = tablica[3*zz]; for (int zzz=0;zzz < ls;zzz += 3) { if (tablica2[3*zzz] < element) { continue; } if (tablica2[3*zzz] == element) { break; } if (tablica[3*zz+2]+tablica[3*zzz+2] > sz) { printf("NIE\n"); goto TEST; } } } printf("TAK\n"); TEST: free(tablica); free(tablica2); } 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 | #include <stdio.h> #include <stdlib.h> int my_compare(const void* j,const void* d) { if (*((int*)j+1) > *((int*)d+1)) { return 1;} return -1; } int main() { int liczba_testow; scanf("%d",&liczba_testow); int vector[4]; for (int a=0;a < liczba_testow;a++) { int ls; int sz; scanf("%d %d",&ls,&sz); int* tablica = (int*) malloc (sizeof(int)*3*ls); int* tablica2 = (int*) malloc (sizeof(int)*3*ls); for (int b=0;b < ls;b++) { scanf("%d %d %d %d",vector,vector+1,vector+2,vector+3); tablica[3*b] = b; tablica[3*b+1] = vector[0]; tablica[3*b+2] = abs(vector[1]-vector[3]); } for (int b=0;b < ls;b++) { scanf("%d %d %d %d",vector,vector+1,vector+2,vector+3); tablica2[3*b] = b; tablica2[3*b+1] = vector[0]; tablica2[3*b+2] = abs(vector[1]-vector[3]); } qsort((void*)tablica,ls,sizeof(int)*3,my_compare); qsort((void*)tablica2,ls,sizeof(int)*3,my_compare); for (int zz=0;zz < ls;zz += 3) { int element = tablica[3*zz]; for (int zzz=0;zzz < ls;zzz += 3) { if (tablica2[3*zzz] < element) { continue; } if (tablica2[3*zzz] == element) { break; } if (tablica[3*zz+2]+tablica[3*zzz+2] > sz) { printf("NIE\n"); goto TEST; } } } printf("TAK\n"); TEST: free(tablica); free(tablica2); } return 0; } |