Input_poj1262_计算几何

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值