hdu 6055 计算几何+暴力


Regular polygon

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 170    Accepted Submission(s): 70


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
 

Source
 

Recommend
liuyiding   |   We have carefully selected several similar problems for you:   6055  6054  6053  6052  6051 
题意: 题意是给了n个点,问着这个图中有多少个正多边形
题解:
因为给出的点都是整数点,所以满足条件的正多边形只有正方形。
先找到两个点,然后枚举其他点,看是否能够找到其他两个满足条件的点。
这样枚举每条边,一个正方形被算了四遍,所以最后的结果要除以4。
一条边两边都可能存在正方形。所以算两遍。
设两个点(x1 , y1)和(x2, y2)那么查询是否存在(x1 + y1-y2, y1+x2-x1),(x2+y1-y2, y2+x2-x1)
与(x1-(y1-y2), y1-(x2-x1)), (x2-(y1-y2), y2-(x2-x1))。假设(x1,y1)在(x2,y2)上面。
代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N= 500;
int vis[N][N];
int a[505][2];
int caculatorCount(int i, int j) {
    int sum = 0;
    int x = a[j][0]-a[i][0];
    int y = a[i][1]-a[j][1];
    if(a[i][0]+y >= 0 && a[i][1]+x >= 0 && a[j][0]+y >= 0 && a[j][1]+x >= 0 &&
       vis[a[i][0]+y][a[i][1]+x] && vis[a[j][0]+y][a[j][1]+x])
        sum++;
    if(a[i][0]-y >=0 && a[i][1]-x >= 0 && a[j][0]-y >= 0 && a[j][1]-x >= 0 &&
        vis[a[i][0]-y][a[i][1]-x] && vis[a[j][0]-y][a[j][1]-x])
        sum++;
    return sum;
}
int main() {
    int n, Count;
    while(scanf("%d", &n) != EOF) {
        Count = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 1; i <= n; i++) {
            scanf("%d%d", &a[i][0], &a[i][1]);
            a[i][0] += 200;
            a[i][1] += 200;
            vis[a[i][0]][a[i][1]] = 1;
        }
        for(int i = 1; i < n; i++)
            for(int j = i+1; j <= n; j++) {
                Count += caculatorCount(i, j);
            }
        printf("%d\n", Count/4);
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值