#include <stdio.h> //#include <climits> //#include <cstdlib> struct car { long int x0; long int y0; long int x1; long int y1; long int target_x0; long int target_y0; long int target_x1; long int target_y1; long int length; long int target; }; int main() { int how_many_times = 0; //FILE * pFile; //pFile = fopen ("sample_tak.txt","r"); //fscanf (pFile, "%d", &how_many_times); scanf ("%d",&how_many_times); for(int how_many_iterator = 0; how_many_iterator < how_many_times; how_many_iterator++) { long int cars_amount = 0; long int parking_height = 0; //fscanf (pFile, "%d", &cars_amount); //fscanf (pFile, "%d", &parking_height); scanf ("%ld",&cars_amount); scanf ("%ld",&parking_height); car *cars = new car[cars_amount]; bool is_possible = true; for(long int cars_iterator = 0; cars_iterator < cars_amount; cars_iterator++) { /* fscanf (pFile, "%d", &cars[cars_iterator].x0); fscanf (pFile, "%d", &cars[cars_iterator].y0); fscanf (pFile, "%d", &cars[cars_iterator].x1); fscanf (pFile, "%d", &cars[cars_iterator].y1); */ scanf ("%ld",&cars[cars_iterator].x0); scanf ("%ld",&cars[cars_iterator].y0); scanf ("%ld",&cars[cars_iterator].x1); scanf ("%ld",&cars[cars_iterator].y1); cars[cars_iterator].length = cars[cars_iterator].y1 - cars[cars_iterator].y0; } for(long int cars_iterator = 0; cars_iterator < cars_amount; cars_iterator++) { /* fscanf (pFile, "%d", &cars[cars_iterator].target_x0); fscanf (pFile, "%d", &cars[cars_iterator].target_x1); fscanf (pFile, "%d", &cars[cars_iterator].target_y0); fscanf (pFile, "%d", &cars[cars_iterator].target_y1); */ scanf ("%ld",&cars[cars_iterator].target_x0); scanf ("%ld",&cars[cars_iterator].target_y0); scanf ("%ld",&cars[cars_iterator].target_x1); scanf ("%ld",&cars[cars_iterator].target_y1); } for(int i = 0; i < cars_amount; i++) { for (int j = 0; j < cars_amount-1; j++) { if (cars[j].x0 > cars[j+1].x0) { car temp = cars[j]; cars[j] = cars[j+1]; cars[j+1] = temp; } } } for(int i = 0; i < cars_amount; i++) { cars[i].target = 0; for(int j = 0; j < cars_amount; j++) { if(cars[i].target_x0 > cars[j].target_x0) { cars[i].target++; } } } for(int i = cars_amount - 1; i > 0; i--) { for(int j = i - 1; j >= cars[i].target; j--) { if(cars[i].length + cars[j].length > parking_height) { is_possible = false; break; } } } if(is_possible) { printf("TAK\n"); } else { printf("NIE\n"); } } // fclose (pFile); //system("pause"); 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | #include <stdio.h> //#include <climits> //#include <cstdlib> struct car { long int x0; long int y0; long int x1; long int y1; long int target_x0; long int target_y0; long int target_x1; long int target_y1; long int length; long int target; }; int main() { int how_many_times = 0; //FILE * pFile; //pFile = fopen ("sample_tak.txt","r"); //fscanf (pFile, "%d", &how_many_times); scanf ("%d",&how_many_times); for(int how_many_iterator = 0; how_many_iterator < how_many_times; how_many_iterator++) { long int cars_amount = 0; long int parking_height = 0; //fscanf (pFile, "%d", &cars_amount); //fscanf (pFile, "%d", &parking_height); scanf ("%ld",&cars_amount); scanf ("%ld",&parking_height); car *cars = new car[cars_amount]; bool is_possible = true; for(long int cars_iterator = 0; cars_iterator < cars_amount; cars_iterator++) { /* fscanf (pFile, "%d", &cars[cars_iterator].x0); fscanf (pFile, "%d", &cars[cars_iterator].y0); fscanf (pFile, "%d", &cars[cars_iterator].x1); fscanf (pFile, "%d", &cars[cars_iterator].y1); */ scanf ("%ld",&cars[cars_iterator].x0); scanf ("%ld",&cars[cars_iterator].y0); scanf ("%ld",&cars[cars_iterator].x1); scanf ("%ld",&cars[cars_iterator].y1); cars[cars_iterator].length = cars[cars_iterator].y1 - cars[cars_iterator].y0; } for(long int cars_iterator = 0; cars_iterator < cars_amount; cars_iterator++) { /* fscanf (pFile, "%d", &cars[cars_iterator].target_x0); fscanf (pFile, "%d", &cars[cars_iterator].target_x1); fscanf (pFile, "%d", &cars[cars_iterator].target_y0); fscanf (pFile, "%d", &cars[cars_iterator].target_y1); */ scanf ("%ld",&cars[cars_iterator].target_x0); scanf ("%ld",&cars[cars_iterator].target_y0); scanf ("%ld",&cars[cars_iterator].target_x1); scanf ("%ld",&cars[cars_iterator].target_y1); } for(int i = 0; i < cars_amount; i++) { for (int j = 0; j < cars_amount-1; j++) { if (cars[j].x0 > cars[j+1].x0) { car temp = cars[j]; cars[j] = cars[j+1]; cars[j+1] = temp; } } } for(int i = 0; i < cars_amount; i++) { cars[i].target = 0; for(int j = 0; j < cars_amount; j++) { if(cars[i].target_x0 > cars[j].target_x0) { cars[i].target++; } } } for(int i = cars_amount - 1; i > 0; i--) { for(int j = i - 1; j >= cars[i].target; j--) { if(cars[i].length + cars[j].length > parking_height) { is_possible = false; break; } } } if(is_possible) { printf("TAK\n"); } else { printf("NIE\n"); } } // fclose (pFile); //system("pause"); return 0; } |