#include<iostream>
#include<cmath>
#include<cstdlib>
#include<vector>
using namespace std;
#define MIN(a,b) ((a)<(b))?(a):(b)
#define MAX(a,b) ((a)>(b))?(a):(b)
class Car{
private:
unsigned int width;
unsigned int height;
unsigned int xpos;
unsigned int xtarget;
unsigned int xdesired;
public:
Car (int,int,int,int);
void setTarget(int);
bool travel(vector<Car>);
bool isAt(int x){return (x>=xpos)&&(x<=xpos+width);};
unsigned int getHeight(){return height;};
};
int getMaxHeight(int x, vector<Car> V)
{
int h=0;
for (vector<Car>::iterator it = V.begin(); it != V.end(); it++)
{
if (it->isAt(x))
h=MAX(h,it->getHeight());
}
return h;
}
vector<Car> cars;
int w;
int main()
{
int t;
cin>>t;
for (int i = 0; i<t; ++i)
{
bool possible=true;
int n,shift=0;
cin>>n>>w;
for(int j = 0; j<n; ++j)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
Car T(x1,y1,x2,y2);
cars.push_back(T);
shift=MAX(shift,x1);
shift=MAX(shift,x2);
}
for(int j = 0; j<n; ++j)
{
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
cars[j].setTarget(MIN(x1,x2));
}
for(int j = 0; j<n; ++j)//test print
{
possible = (possible && cars[j].travel(cars));
if (!possible)break;
}
if(possible)
{
cout<<"TAK"<<endl;
}
else
{
cout<<"NIE"<<endl;
}
}
}
Car::Car(int x1,int y1, int x2, int y2)
{
width = abs(x1 - x2);
height= abs(y1 - y2);
xpos = MIN(x1,x2);
}
void Car::setTarget(int x){xtarget = x;}
bool Car::travel(vector<Car> V)
{
if (xpos==xtarget)
{
return true;
}
if (xpos>xtarget)
{
for (int i = xtarget; i<xpos; i++)
{
int freespace = w - getMaxHeight(i,cars);
if(freespace<height)
{
return false;
}
}
return true;
}
if (xpos<xtarget)
{
for (int i = xpos+1; i <= xtarget; i++)
{
int freespace = w - getMaxHeight(i,cars);
if(freespace<height)
{
return false;
}
}
return true;
}
}
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 | #include<iostream> #include<cmath> #include<cstdlib> #include<vector> using namespace std; #define MIN(a,b) ((a)<(b))?(a):(b) #define MAX(a,b) ((a)>(b))?(a):(b) class Car{ private: unsigned int width; unsigned int height; unsigned int xpos; unsigned int xtarget; unsigned int xdesired; public: Car (int,int,int,int); void setTarget(int); bool travel(vector<Car>); bool isAt(int x){return (x>=xpos)&&(x<=xpos+width);}; unsigned int getHeight(){return height;}; }; int getMaxHeight(int x, vector<Car> V) { int h=0; for (vector<Car>::iterator it = V.begin(); it != V.end(); it++) { if (it->isAt(x)) h=MAX(h,it->getHeight()); } return h; } vector<Car> cars; int w; int main() { int t; cin>>t; for (int i = 0; i<t; ++i) { bool possible=true; int n,shift=0; cin>>n>>w; for(int j = 0; j<n; ++j) { int x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; Car T(x1,y1,x2,y2); cars.push_back(T); shift=MAX(shift,x1); shift=MAX(shift,x2); } for(int j = 0; j<n; ++j) { int x1,x2,y1,y2; cin>>x1>>y1>>x2>>y2; cars[j].setTarget(MIN(x1,x2)); } for(int j = 0; j<n; ++j)//test print { possible = (possible && cars[j].travel(cars)); if (!possible)break; } if(possible) { cout<<"TAK"<<endl; } else { cout<<"NIE"<<endl; } } } Car::Car(int x1,int y1, int x2, int y2) { width = abs(x1 - x2); height= abs(y1 - y2); xpos = MIN(x1,x2); } void Car::setTarget(int x){xtarget = x;} bool Car::travel(vector<Car> V) { if (xpos==xtarget) { return true; } if (xpos>xtarget) { for (int i = xtarget; i<xpos; i++) { int freespace = w - getMaxHeight(i,cars); if(freespace<height) { return false; } } return true; } if (xpos<xtarget) { for (int i = xpos+1; i <= xtarget; i++) { int freespace = w - getMaxHeight(i,cars); if(freespace<height) { return false; } } return true; } } |
English