wustoj1280What’ s Soapbear(简单计算几何)
来源:互联网 发布:java经典书籍分享 编辑:程序博客网 时间:2024/05/18 01:26
1280: What’ s Soapbear
Time Limit: 2 Sec Memory Limit: 128 MB
[Submit][Status][Web Board]
Problem Description
Soapbear is a bear who likes collecting soaps, of course not picking up soaps. Soapbear has collected many soaps of different shapes. To simplify the problem, you can assume they are all polygons without self-intersect. Besides, since Soapbear has special interest in anything with axial symmetry, all of his soap are of axial symmetry. Recently Wallace picked up some soaps and he wonders which of them may belong to Soapbear.
Input
There are multiple test cases in the input file. There first line of the input is an integer T indicates the number of the test cases. Each test case starts with a line containing a integer N (3 <= N <= 12), the number of vertexes of the soap. Then N lines follow, each of which contains two integers Xi and Yi, indicate the coordinate of the i-th vertex in Cartesian coordinate system. All the integers given are no more than 10000 in absolute value. All the coordinates are given in clockwise order.
Output
For each test case, if the polygon is of axial symmetry, print a line “The soap may belong to the bear !”, otherwise print a line “The soap does not belong to the bear !” (without quotation marks).
Sample Input
2120 10 31 31 42 42 54 54 33 33 22 22 144 04 26 27 0
Sample Output
The soap may belong to the bear !The soap does not belong to the bear !
HINT
Source
Difficulty
题目大意:给你一个多边形,让你判断这个多边形是不是轴对称图形。
解题思路:由于最多只有十二个点,可以直接暴力枚举。如果轴对称,肯定有个对称轴,我们枚举任意两个点的中垂线来作为对称轴。然后处理其它的点,如果点在中垂线上,直接不考虑这点,其它的点都需要配对,这样才可以达到轴对称。详见代码:
题目地址:http://wusttest.sinaapp.com/problem.php?id=1280
AC代码:
#include<iostream>#include<cmath>#include<cstdio>#include<sstream>#include<cstdlib>#include<string>#include<string.h>#include<cstring>#include<algorithm>#include<vector>#include<map>#include<set>#include<stack>#include<list>#include<queue>#include<ctime>#include<bitset>#define eps 1e-6#define INF 0x3f3f3f3f#define PI acos(-1.0)#define ll __int64#define LL long long#define lson l,m,(rt<<1)#define rson m+1,r,(rt<<1)|1#define M 1000000007using namespace std; #define Maxn 15struct nod{ double x; double y;}node[Maxn]; int visi[Maxn]; int main(){ int t,n,i,j,k,l,p; cin>>t; while(t--) { cin>>n; for(i=0;i<n;i++) cin>>node[i].x>>node[i].y; double x,y; int flag=0; nod p1,p2,p3; for(i=0;i<n&&!flag;i++) { for(j=i+1;j<n&&!flag;j++) { memset(visi,0,sizeof(visi)); visi[i]=1; visi[j]=1; x=(node[i].x+node[j].x)/2; y=(node[i].y+node[j].y)/2; p1.x=node[j].x-node[i].x; p1.y=node[j].y-node[i].y; for(k=0;k<n;k++) { if(visi[k]) continue; p2.x=node[k].x-x; p2.y=node[k].y-y; if(fabs(p1.x*p2.x+p1.y*p2.y)<eps) { visi[k]=1; continue; } } for(k=0;k<n;k++) { if(visi[k]) continue; for(p=0;p<n;p++) { if(p==k||visi[p]) continue; double x1,y1; x1=(node[k].x+node[p].x)/2; y1=(node[k].y+node[p].y)/2; p2.x=x1-x; p2.y=y1-y; p3.x=node[k].x-node[p].x; p3.y=node[k].y-node[p].y; if(fabs(x1-x)<eps&&fabs(y1-y)<eps) continue; if(fabs(p1.x*p2.x+p1.y*p2.y)<eps&&fabs(p2.x*p3.x+p2.y*p3.y)<eps) { visi[k]=1; visi[p]=1; flag=1; break; } } } int tt=0; for(l=0;l<n;l++) if(!visi[l]) tt=1; if(tt==0) flag=1; } } if(flag) puts("The soap may belong to the bear !"); else puts("The soap does not belong to the bear !"); } return 0;} /*2364 24 04 -26 46 26 0 30 02 01 2*/
0 0
- wustoj1280What’ s Soapbear(简单计算几何)
- UVA 11178 - Morley's Theorem 简单的计算几何
- poj1410 简单计算几何
- zoj3728_Collision(简单计算几何)
- uva5984(简单计算几何)
- 计算几何简单模板
- Rectangles 简单几何计算
- 20140731 【南华大学 ACM】 1269 What’ s Soapbear
- POJ 2624 简单计算几何
- poj1269 简单的计算几何
- hdu 4097 简单计算几何
- POJ 1675 简单计算几何
- hdu 4998 简单计算几何
- HDU 5533 简单计算几何
- hdu 4643(简单计算几何)
- [hdu] 6167 简单计算几何
- POJ2318 计算几何简单题
- HDU 1756 Cupid's Arrow 计算几何
- Delphi中的 UTC 时间与DateTime及XMLDateTime
- 使用Quartus II进行CPLD仿真
- 双向循环链表经典案例,20孩子报数,7的倍数或数字中含有7,不出声,数数的方向逆转
- poj2378,Tree Cutting
- .NET---物件导向与类别设计
- wustoj1280What’ s Soapbear(简单计算几何)
- 聚类算法之MST算法 java实现版本
- php语法
- 单元测试准则
- 使用windows远程桌面连接拷贝远程电脑上文件到本地的方法
- 关于android中SQLite基本操作
- chapter 3(第二部分)
- 用户名验证
- 死锁