PAT TOP 1011. Cut Rectangles (35)

问题描述:

1011. Cut Rectangles (35)

时间限制
150 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
LIU, Rujia

When a rectangle is cut by a straight line, we can easily obtain two polygons as the result. But the reversed problem is harder: given two polygons, your task is to check whether or not they could be obtained by cutting a rectangle.

To give you more trouble, the input polygons are possibly moved, rotated (90 degrees, 180 degrees, or 270 degrees counter-clockwise), or even flipped (mirrored).

It is assumed that the original rectangle's edges are parallel to the axis.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N(<=20), and then N pairs of polygons are given. Each polygon is described in the format:

k x1 y1 ... xk yk

where k (2 < k <= 10) is the number of vertices on the polygon, and (xi, yi) (0 <= xi, yi <= 108) are the coordinates of the vertices, given in either clockwise or counter-clockwise order.

Note: there is no redundant vertex. That is, it is guaranteed that all the vertices are distinct for each polygon, and that no three consecutive vertices are on the same line.

Output Specification:

For each pair of polygons, print in a line either "YES" or "NO" as the answer.

Sample Input:
8
3 0 0 1 0 1 1
3 0 0 1 1 0 1
3 0 0 1 0 1 1
3 0 0 1 1 0 2
4 0 4 1 4 1 0 0 0
4 4 0 4 1 0 1 0 0
3 0 0 1 1 0 1
4 2 3 1 4 1 7 2 7
5 10 10 10 12 12 12 14 11 14 10
3 28 35 29 35 29 37
3 7 9 8 11 8 9
5 87 26 92 26 92 23 90 22 87 22
5 0 0 2 0 1 1 1 2 0 2
4 0 0 1 1 2 1 2 0
4 0 0 0 1 1 1 2 0
4 0 0 0 1 1 1 2 0
Sample Output:
YES
NO
YES
YES
YES
YES
NO
YES

很暴力很暴力的一题,会一些几何知识和会用if-else就基本能过了。。。

我在无脑提交调试的时候莫名其妙地就过了。。。


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<bits/stdc++.h>
using namespace std;
int main()
{
//  ios::sync_with_stdio(false);
 //   freopen("data.txt","r",stdin);
    int n,k,x;
	int c1,c2;
    scanf("%d",&n);
    for(;n--;)
    {
    	int p411=-1,p412=-1,p421=-1,p422=-1;
    	vector<pair<int,int> > v1,v2; 
    	bool flag=false;
    	pair<int,int> p1(0,0);
    	pair<int,int> p2(0,0);
    	scanf("%d",&k);
    	for(int i=0;i<k;i++)
    	{
    		scanf("%d %d",&c1,&c2);
    		if((!v1.empty())&&(c1-v1.back().first)&&(c2-v1.back().second))
    		{
    			if(!p1.first||!p1.second)
    			{
					p1.first=abs(c1-v1.back().first);
					p1.second=abs(c2-v1.back().second);
					if(k>3)
					{
						p411=i-1;
						p412=i;
					}
				}
				else
				{
					p1.first=-1;
					p1.second=-1;					
				}
			}
    		v1.push_back(pair<int,int>(c1,c2));
		}
		if(!p1.first||!p1.second)
		{
			p1.first=abs(v1.front().first-v1.back().first);
			p1.second=abs(v1.front().second-v1.back().second);
			if(k>3)
			{
				p411=k-1;
				p412=0;
			}
		}
		else if((v1.front().first-c1)&&(v1.front().second-c2))
		{
			p1.first=-1;
			p1.second=-1;
		}
		scanf("%d",&k);
    	for(int i=0;i<k;i++)
    	{
    		scanf("%d %d",&c1,&c2);
    		if((!v2.empty())&&(c1-v2.back().first)&&(c2-v2.back().second))
    		{		
				if(!p2.first||!p2.second)
				{
					p2.first=abs(c1-v2.back().first);
					p2.second=abs(c2-v2.back().second);
					if(k>3)
					{
						p421=i-1;
						p422=i;
					}
				}
				else
				{
					p2.first=-2;
					p2.second=-2;
				}
			}
    		v2.push_back(pair<int,int>(c1,c2));
		}
		if(!p2.first||!p2.second)
		{
			p2.first=abs(v2.front().first-v2.back().first);
			p2.second=abs(v2.front().second-v2.back().second);
			if(k>3)
			{
				p421=k-1;
				p422=0;
			}			
		}
		else if((v2.front().first-c1)&&(v2.front().second-c2))
		{
			p2.first=-2;
			p2.second=-2;
		}
		if(p1.first>p1.second)
		swap(p1.first,p1.second);
		if(p2.first>p2.second)
		swap(p2.first,p2.second);
		if(p1==p2)
		{
			if(v1.size()==3)
			flag=true;
			else if(v1.size()==4)
			{
				flag=true;
				if(v2.size()==4)
				{
					if(!p1.first)
					flag=true;
					else if(p1.first!=p1.second)
					{
						int m1=max(abs(v1[(p411+2)%4].first-v1[(p411+3)%4].first),abs(v1[(p411+2)%4].second-v1[(p411+3)%4].second));
						int m2=max(abs(v2[(p421+2)%4].first-v2[(p421+3)%4].first),abs(v2[(p421+2)%4].second-v2[(p421+3)%4].second));
						if(m1!=m2)
						flag=false;
					}
				}
				else if(v2.size()>4)
				flag=false;
			}
			else if(v1.size()==5)
			{
				if(v2.size()==3)
				flag=true;
			}
		}
		if(flag)
		printf("YES\n");
		else
		printf("NO\n");
	}
  	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值