2013
12-09

# Input

In a recent programming contest, one of the problems was about tiling floors with rectangular tiles. The input specification reads like this:

The input contains several floors. The first line of the input gives the number of floors.

Each floor is described in several lines. The first line contains two positive integers: the length and width of the floor, in millimeters. A floor is at most 40 000 mm long or wide. The next line contains a single number: the number t of tiles (1 <= t <= 100). The following t lines each contain the description of a tile. A tile is given as four integers:

xl yl xh yh

where (xl, yl) are the coordinates of the lower left corner of the tile, and (xh, yh) are the coordinates of the upper rightmost corner of the tile. A tile always has a positive area. The order of the coordinates of the floor and those of the tile coincide, of course.

You may assume that the tiles are mutually disjoint, and cover the floor, the whole floor, and nothing but the floor.

The last line of this specification raised some problems. Not for the contestants, but for the judges. Some of the test cases consist of many tiles. How can we be sure that our input file meets this condition? What we need is a checking program that verifies this condition.

Given an input file in the above format, find out for each floor whether the tiles

1. are disjoint,
2. do not lie outside the floor,
3. do cover the floor.

The input contains several floors. The first line of the input gives the number of floors. Each floor is described in several lines. The first line contains two positive integers: the length and width of the floor, in millimeters. A floor is at most 40 000 mm long or wide. The next line contains a single number: the number t of tiles (1 <= t <= 100). The following t lines each contain the description of a tile. A tile is given as four integers:

xl yl xh yh

where (xl, yl) are the coordinates of the lower left corner of the tile, and (xh, yh) are the coordinates of the upper rightmost corner of the tile. A tile always has a positive area. The order of the coordinates of the floor and those of the tile coincide, of course.

For each floor the output contains a single line, containing one of the following words:

NONDISJOINT if overlapping tiles occur;

NONCONTAINED if no overlapping tiles occur, but some tiles go outside the floor;

NONCOVERING if no overlapping tiles occur, and no tiles go outside the floor, but some parts of the floor are not covered;

OK if none of these is true.

4
4 3
2
0 0 2 2
1 1 5 5
4 3
2
0 0 2 2
-2 2 5 5
4 3
2
0 0 2 2
2 0 4 2
4 3
3
0 0 2 2
2 0 4 2
0 2 4 3 

NONDISJOINT
NONCONTAINED
NONCOVERING
OK 

2.是否有出界外的
3.是否有空隙，
4.在都满足1,2,3的情况下输出“OK”，

#include<stdio.h>

#include<math.h>

#include<iostream>

using namespace std;

struct Tile

{

int x1,y1;

int x2,y2;

int s;

}p[101];

int main()

{

int n,i,j,k;

int t1,t2,t3;

int a,b,sum,m,c1,c2,t;

while(scanf("%d",&n)!=EOF)

{

while(n--)

{

t1=t2=t3=0;

sum=0;

scanf("%d%d",&a,&b);

scanf("%d",&m);

t=(a>b? a:b);

for(i=0;i<m;i++)

{

scanf("%d%d%d%d",&p[i].x1,&p[i].y1,&p[i].x2,&p[i].y2);

c1=abs(p[i].x1-p[i].x2);

c2=abs(p[i].y1-p[i].y2);

p[i].s=c1*c2;

sum+=p[i].s;

if(p[i].x1<0||p[i].x2<0||p[i].y1 <0||p[i].y2 <0)//判断是否过界

t2=1;

if(p[i].x1>t||p[i].x2>t||p[i].y1>t||p[i].y2>t)

t2=1;

}

if(sum<a*b)//判断是否有空隙

t3=1;

for(i=0;i<m;i++)//判断是否有重叠

{ if(t1)break;

for(j=i+1;j<m;j++)

{

if((p[j].x1>=p[i].x2)||(p[j].x2<=p[i].x1)||(p[j].y1>=p[i].y2)||(p[j].y2<=p[i].y1))

continue;

else

{t1=1;

break;

}

}

}

// printf("t1=%d t2=%d t3=%d\n",t1,t2,t3);

if(t1)

printf("NONDISJOINT\n");

else if(t2)

printf("NONCONTAINED\n");

else if(t3)

printf("NONCOVERING\n");

else

printf("OK\n");

}

}

return 0;

}



1. 问题3是不是应该为1/4 .因为截取的三段，无论是否能组成三角形， x， y-x ，1-y,都应大于0，所以 x<y,基础应该是一个大三角形。小三角是大三角的 1/4.