Input_poj1262_计算几何

来源:互联网 发布:乐知英语的公司在哪 编辑:程序博客网 时间:2024/04/26 01:46

Description


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.
Problem
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.

Input


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.

Output


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.

Analysis


纯模拟?不是很明白题目的意义
记录瓷砖的上、下、左、右,判断一下冲突就可以了

Code


#include <stdio.h>#include <cmath>using namespace std;struct tile{    int u,d,l,r;    long long S;}v[1001];int conf(tile x,tile y){    return !(x.u<=y.d||x.d>=y.u||x.l>=y.r||x.r<=y.l);}int main(){    int n,t,a,b;    while (~scanf("%d",&n))        while (n--)        {            int ans1=0,ans2=0,ans3=0;            long long sumArea=0;            scanf("%d%d%d",&a,&b,&t);            int lim=a>b?a:b;            for (int i=1;i<=t;i++)            {                int x1,y1,x2,y2;                scanf("%d%d%d%d",&x1,&y1,&x2,&y2);                int tmp=((x1-x2)*(y1-y2));                if (tmp<0)                    tmp=-tmp;                v[i]=(tile){x2,x1,y1,y2,tmp};                if (x1>lim||x1<0||x2<0||x2>lim||y1>lim||y1<0||y2<0||y2>lim)                    ans2=1;                    sumArea+=v[i].S;            }            for (int i=1;i<=t-1;i++)                for (int j=i+1;j<=t;j++)                    if (conf(v[i],v[j]))                    {                        ans1=1;                        break;                    }            if ((sumArea<a*b))                ans3=1;            if (ans1)                printf("NONDISJOINT\n");            else                if(ans2)                    printf("NONCONTAINED\n");                else                    if (ans3)                        printf("NONCOVERING\n");                    else                        printf("OK\n");        }    return 0;}
1 0
原创粉丝点击