hdu6055—Regular polygon(正方形的判定)

题目链接:传送门

Regular polygon

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


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


解题思路:平面上的整点只能构成正方形,枚举正方形的两个点,再判断是否存在构成该正方形的另外两个点


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int>PA;
const int N = 80010;
const int M = 1090;
const int INF = 0x3fffffff;
const int mod = 1e9+7;
const double eps = 1e-8;
const double PI = acos(-1.0);

int graph[M][M];
vector<PA>st;

//平面区域内给n个整点
//求一个平面区域内的正方形个数

bool judge( int x , int y )
{
    //忘了判断是否越界,wa了无数次
    if( x+205 < 0 || y+205 < 0 ) return false;
    if( graph[x+205][y+205] ) return true;
    else return false;
}

int main()
{
    int n;
    while( ~scanf("%d",&n) ){
        memset( graph , 0 , sizeof(graph) );
        st.clear();
        int a,b;
        for( int i = 0 ; i < n ; ++i ){
            scanf("%d%d",&a,&b);
            graph[a+205][b+205] = 1;
            st.push_back(PA(a,b));
        }
        int x1,y1,x2,y2,cnt = 0;
        for( int i = 0 ; i < n ; ++i ){
            for( int j = 0 ; j < n ; ++j ){
                if( i == j ) continue;
                x1 = st[i].first;
                y1 = st[i].second;
                x2 = st[j].first;
                y2 = st[j].second;
                if( y1 == y2 ) continue;
                if( x1>=x2&&y1>=y2&&judge(x1-(y1-y2),y1+(x1-x2))
                   &&judge(x2-(y1-y2),y2+(x1-x2)) ) cnt++;
            }
        }
        printf("%d\n",cnt);
    }
    return 0;
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值