2017 Multi-University Training Contest - Team 2 1011 Regular polygon

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
4
0 0
0 1
1 0
1 1
6
0 0
0 1
1 0
1 1
2 0
2 1
 

 

Sample Output
1
2
 
判断有多少个正方形,几何题目。
假设正方形的四个点 左下(x1,y1),右下(x2,y2),右上(x3,y3),左上(x4,y4),其中(x1,y1)和(x3,y3)是一对对角点。一定有y3-y1 = x3-x1。
(nx+dy)&1 和(ny+dx)&1 不成立时,说明这两个点一定不能组成一个正方形的对角点,以(x1,y1),(x3,y3)当例子,(nx+dy) = x1+x3+y3-y1 = x1+x3+x3-x1 = 2*x3,
ny+dx = y1+y3+y3-y1 = 2*y3,一定不是奇数。其中((nx+dy)/2,(ny+sg*dx)/2)是求(x3,y1)即(x2,y2),((nx-dy)/2,(ny-sg*dx)/2)是求(x1,y3)即(x4,y4)。
由于一个正方形重复计算了两遍,结果除2就是答案了。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <set>
 5 using namespace std;
 6 int x[550], y[550];
 7 int main() {
 8     int n;
 9     while(scanf("%d",&n)!=EOF) {
10         set<pair<int,int> > st;
11         for(int i = 0; i < n; i ++) {
12             scanf("%d%d",&x[i],&y[i]);
13             st.insert(make_pair(x[i],y[i]));
14         }
15         int ans = 0;
16         for(int i = 0; i < n; i ++) {
17             for(int j = i+1; j < n; j ++) {
18                 int nx = x[i]+x[j], dx = max(x[i],x[j])-min(x[i],x[j]);
19                 int ny = y[i]+y[j], dy = max(y[i],y[j])-min(y[i],y[j]);
20                 if((nx+dy)&1 || (ny+dx)&1) continue;
21                 int sg = ((x[i]-x[j])*(y[i]-y[j]) < 0)?1:-1;
22                 if(st.count(make_pair((nx+dy)/2,(ny+sg*dx)/2)) && st.count(make_pair((nx-dy)/2,(ny-sg*dx)/2)))
23                     ans++;
24             }
25         }
26         printf("%d\n",ans/2);
27     }
28     return 0;
29 }

 

转载于:https://www.cnblogs.com/xingkongyihao/p/7248716.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值