• HDU 6055 Regular polygon


    Regular polygon

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


    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 
    /*
    * @Author: Lyucheng
    * @Date:   2017-07-27 14:26:58
    * @Last Modified by:   Lyucheng
    * @Last Modified time: 2017-07-28 15:43:15
    */
    /*
     题意:给你一个点阵,让你找多边形的个数,因为点都是整数所以只可能是正方形
    */
    
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    
    #define MAXN 5005
    #define MAXM 2005
    #define EXP 1e-6
    using namespace std;
    
    struct Point{
        int x,y;
        Point(){}
        Point(int _x,int _y){
            x=_x;
            y=_y;
        }
        bool operator < (const Point & other) const{
            if(x==other.x)
                return y<other.y;
            return x<other.x;
        }
    }point[MAXN];
    int n;
    bool vis[MAXM][MAXM];
    
    bool ok(Point a,Point b){//对点
        double ax=(a.x+a.y+b.x-b.y)*1.0/2;
        double ay=(-a.x+a.y+b.x+b.y)*1.0/2;
        double bx=(a.x-a.y+b.x+b.y)*1.0/2;
        double by=(a.x+a.y-b.x+b.y)*1.0/2;
    
        if(ax-(int)ax>EXP||bx-(int)bx>EXP||ay-(int)ay>EXP||by-(int)by>EXP)
            return false;
        if(ax<0||ay<0||bx<0||by<0)
            return false;
        
        if(vis[(int)ax][(int)ay]==true&&vis[(int)bx][(int)by]==true)
            return true;
        return false;
    }
    
    inline void init(){
        memset(vis,false,sizeof vis);
    }
    
    int main(){
        // freopen("in.txt", "r", stdin);
        // freopen("out.txt", "w", stdout);
        while(scanf("%d",&n)!=EOF){
            init();
            for(int i=0;i<n;i++){
                scanf("%d%d",&point[i].x,&point[i].y);
                point[i].x+=100;
                point[i].y+=100;
                vis[point[i].x][point[i].y]=true;
            }
            sort(point,point+n);
            int res=0;
            for(int i=0;i<n;i++){
                for(int j=i+1;j<n;j++){
                    if(ok(point[i],point[j])==true){
                        res++;
                    }
                }
            }
            printf("%d
    ",res/2);
        }
        return 0;
    }
  • 相关阅读:
    封装cookie
    敏感词过滤
    面向对象改成选项卡
    正则表达式
    cookie
    DOM
    系统对象
    cookie记录用户名
    6个原则
    23中设计模式
  • 原文地址:https://www.cnblogs.com/wuwangchuxin0924/p/7250636.html
Copyright © 2020-2023  润新知