#include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <strings.h> #define PARAMS 4 #define MAX_COMPANIES 100000 #define tabSize PARAMS*MAX_COMPANIES unsigned int buf[tabSize]; bool lus(unsigned int n) { int i,j; long long int min = buf[0] * buf[2]; long long int max = buf[1] * buf[3]; long long minTmp; long long maxTmp; int minIdx = 0; int maxIdx = 0; int same = 1; for(i = 4; i < n; i = i + 4) { minTmp = buf[i] * buf[i+2]; maxTmp = buf[i+1] * buf[i+3]; if((min == minTmp)&&(max == maxTmp))same++; if(minTmp < min) { min = minTmp; minIdx = i/4; if(maxTmp == max)maxIdx = i/4; } if(maxTmp > max) { max = maxTmp; maxIdx = i/4; if(minTmp == min)minIdx = i/4; } } if((maxIdx == minIdx)&&(same != n/4))return true; return false; } int main() { int t,n,i,j,in; scanf("%d",&t); // tests for(i = 0; i < t; i++) { scanf("%d",&n); // companies for(j = 0; j < n*4; j++) { scanf("%d",&in); buf[j] = in; } printf(lus(n*4) ? "TAK\n" : "NIE\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 56 57 58 | #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <strings.h> #define PARAMS 4 #define MAX_COMPANIES 100000 #define tabSize PARAMS*MAX_COMPANIES unsigned int buf[tabSize]; bool lus(unsigned int n) { int i,j; long long int min = buf[0] * buf[2]; long long int max = buf[1] * buf[3]; long long minTmp; long long maxTmp; int minIdx = 0; int maxIdx = 0; int same = 1; for(i = 4; i < n; i = i + 4) { minTmp = buf[i] * buf[i+2]; maxTmp = buf[i+1] * buf[i+3]; if((min == minTmp)&&(max == maxTmp))same++; if(minTmp < min) { min = minTmp; minIdx = i/4; if(maxTmp == max)maxIdx = i/4; } if(maxTmp > max) { max = maxTmp; maxIdx = i/4; if(minTmp == min)minIdx = i/4; } } if((maxIdx == minIdx)&&(same != n/4))return true; return false; } int main() { int t,n,i,j,in; scanf("%d",&t); // tests for(i = 0; i < t; i++) { scanf("%d",&n); // companies for(j = 0; j < n*4; j++) { scanf("%d",&in); buf[j] = in; } printf(lus(n*4) ? "TAK\n" : "NIE\n"); } return (0); } |