poj1262

链接:http://poj.org/problem?id=1262 

Input

Time Limit: 1000MS

Memory Limit: 10000K

Total Submissions: 629

Accepted: 268

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.

Sample Input

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

Sample Output

NONDISJOINT

NONCONTAINED

NONCOVERING

OK

Source

题目大意:给出地板的长度和宽度,及瓷砖的位置,按照瓷砖覆盖的情况输出答案:情况1.是否存在重叠情况:

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;

}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值