hdu 6055 Regular polygon
来源:互联网 发布:ui设计php 编辑:程序博客网 时间:2024/04/29 14:59
Regular polygon
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2184 Accepted Submission(s): 859
Problem Description
On a two-dimensional plane, give you n integer points. Your task is to figure out how many different regular polygon these points can make.
Input
The input file consists of several test cases. Each case the first line is a numbers N (N <= 500). The next N lines ,each line contain two number Xi and Yi(-100 <= xi,yi <= 100), means the points’ position.(the data assures no two points share the same position.)
Output
For each case, output a number means how many different regular polygon these points can make.
Sample Input
40 00 11 01 160 00 11 01 12 02 1
Sample Output
12
这是一道几何题,题意很简单,就是平面周中有n个点,问能组成多少个不同的正方形?
题目分析:根据题目要求n<=500,数据量不是很大,因此我们可以遍历每两个点,判断以这两点连线为边的正方形有几个,由于正方形有四条边,因此最后结果除以4就可以了。
对于每两个点,以他们为边的正方形的两位两点就容易用这两点的坐标求出,然后判断这两个点是否存在(二分法判断)就可以判断是否是正方形的一边了
代码如下:
//1011#include <bits/stdc++.h>using namespace std;int x[510],y[510],xy[510];bool ef(int p,int q,int t)//二分查找点{int m;if(p==q){if(xy[p]==t)return 1;elsereturn 0;}m=(p+q)/2;if(xy[m]==t){return 1;}else{if(xy[m]<t)return ef(m+1,q,t);elsereturn ef(p,m,t);}}bool qfind(int x,int y,int n){int t;t=(x+200)*1000+y+200;return ef(0,n-1,t);}int js(int x1,int y1,int x2,int y2,int n)//判断两点有几个正方形{int a1,b1,a2,b2;int ans=0;a1=x2+y1-y2;b1=y2+x2-x1;a2=x1+y1-y2;b2=y1+x2-x1;if(qfind(a1,b1,n)&&qfind(a2,b2,n))ans++;a1=x2-y1+y2;b1=y2-x2+x1;a2=x1-y1+y2;b2=y1-x2+x1;if(qfind(a1,b1,n)&&qfind(a2,b2,n))ans++;return ans;}int main(){std::ios::sync_with_stdio(false);int n;int a,b,i,j,ans;while(cin>>n){for(i=0;i<n;i++){cin>>a>>b;x[i]=a;y[i]=b;xy[i]=(a+200)*1000+b+200;}sort(xy,xy+n);ans=0;for(i=0;i<n-1;i++)//遍历任意两点{for(j=i+1;j<n;j++){ans+=js(x[i],y[i],x[j],y[j],n);}}cout<<ans/4<<endl;//输出结果}return 0;}
阅读全文
0 0
- [HDU]-6055 Regular polygon
- hdu-6055-Regular polygon
- Regular polygon HDU 6055
- hdu--6055--Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- hdu 6055 Regular polygon
- hdu 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU 6055 Regular polygon
- HDU-6055 Regular polygon
- HDU-6055-Regular polygon
- 【HDU 6055 Regular polygon】+ map
- Regular polygon(HDU 6055)
- HDU 6055 Regular polygon【几何】
- 数据冒险之栈
- 51nod 1267 4个数和为0
- [Leetcode] 321. Create Maximum Number 解题报告
- 顺序循环队列的基本操作(2017.7.26)
- [US Giants] 六. Linked List
- hdu 6055 Regular polygon
- scala把序列分解成子集(group by,partition)
- hdu2098 分拆素数和(C语言)
- 【转】BGP基本配置与总结 (二)
- [Muduo网络库源码分析] (3) base/CountDownLatch.cc_h_“倒计时门闩”同步
- 超详细SQL SERVER 2016跨网段和局域网发布订阅配置图解和常见问题
- 锁定电脑屏幕,相当于“Win + L” 锁定效果
- ScrollView滚动层容器与button点击事件
- C语言制作植物大战僵尸无限阳光修改器