Input_poj1262_计算几何
2016-09-02 21:50
218 查看
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; }
相关文章推荐
- [计算几何] POJ 1873 暴力+凸包
- [计算几何]POJ 1375 点对圆的切线+线段重叠
- 【转载】POJ 计算几何入门题目推荐
- POJ 1556 The Doors(Dijkstra+计算几何)
- 计算几何 POJ 2826 An Easy Problem?! (线段位置判断并且求交点)
- [计算几何]POJ 1031 计算点对多边形的偏转角度
- poj 2507 crossed ladders(计算几何,二分)
- POJ 1106 计算几何
- poj 1434 --Fill the Cisterns!(计算几何,二分)
- poj 2957 计算几何向量的旋转
- POJ 计算几何入门题目推荐
- POJ 3304 计算几何
- POJ计算几何题目【转】
- POJ1269 Intersecting Lines 计算几何 C语言
- JOJ1076 && POJ1039 Pipe 经典计算几何
- [计算几何]POJ 1556 判断线段相交+Dijkstra
- POJ 1113 WALL(凸包-计算几何)
- [Poj 2187] 计算几何之凸包(二) {更高效的算法}
- POJ 1039 Pipe 计算几何题目。。
- POJ题目分类---计算几何