zoukankan      html  css  js  c++  java
  • hdu 6055 Regular polygon

    Regular polygon

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

    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个点的坐标(x,y),问能组成多少正方形
    题目中说找正多边形,正多边形的要求:各条边相等,各个角相等。然而要在格点上,只有正方形才符合要求。
     
    题解:
    已知正方形对角两点坐标(a,b) 与 (c,d),经推导,则另外对角两点坐标为( (   a  + b + c - d )  /  2 ,( - a + b + c + d ) / 2 ) 与 (  ( a - b +  c + d ) / 2 , ( a + b - c + d ) / 2  )

     注意下标越界问题,和与原来的对角的两个点重合。

     
    #include <iostream>
    //#include<bits/stdc++.h>
    #include<cstdio>
    #include<algorithm>
    #include<cstring>
    #include<cmath>
    using namespace std;
    struct node
    {
        int x,y;
    }a[505];
    
    int n,sum;
    bool vis[205][205];
    
    bool ok( int x,int y) //是否越过界线
    {
        if (x<0 || x>200 || y<0 || y>200) return 0;
          return 1;
    }
    bool same(int x,int y,int p,int q)  //判断和原来对角线的两个点有没有重合
    {
        if (x==a[p].x && y==a[p].y) return 0;
        if (x==a[q].x && y==a[q].y) return 0;
         return 1;
    }
    int main()
    {
        while(~scanf("%d",&n))
        {
            memset(vis,0,sizeof(vis));
            for(int i=1;i<=n;i++)
            {
                int x,y;
                scanf("%d%d",&x,&y);
                a[i].x=x+100;
                a[i].y=y+100;
                vis[a[i].x][a[i].y]=1;
            }
            sum=0;
            for(int i=1;i<=n;i++)
                for(int j=i+1;j<=n;j++)
            {
                int x3=(a[i].x+a[i].y+a[j].x-a[j].y);
                int y3=(-a[i].x+a[i].y+a[j].x+a[j].y);
                int x4=(a[i].x-a[i].y+a[j].x+a[j].y);
                int y4=(a[i].x+a[i].y-a[j].x+a[j].y);
                if (x3%2!=0 || y3%2!=0 || x4%2!=0 || y4%2!=0) continue;
                x3/=2; y3/=2; x4/=2; y4/=2;
                if (ok(x3,y3) && ok(x4,y4))
                    if (vis[x3][y3] && vis[x4][y4])
                       if (same(x3,y3,i,j) && same(x4,y4,i,j))
                          sum++;
    
    
            }
            printf("%d
    ",sum/2);
        }
        return 0;
    }
  • 相关阅读:
    内置函数
    map,reduce和filter函数
    函数式编程和尾调用
    函数作用域,匿名函数
    全局变量和局部变量
    函数和过程
    百分号字符串拼接
    集合关系运算交,差,并集
    C#基础-压缩文件及故障排除
    【QQ】前端实现QQ会话功能
  • 原文地址:https://www.cnblogs.com/stepping/p/7250525.html
Copyright © 2011-2022 走看看