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;
    }
  • 相关阅读:
    分布式
    pytest+allure+jenkins
    Pytest-参数化和unittest-ddt的对比(两种数据驱动的对比)
    pytest- fixture个人理解总结
    os路径拼接时,比如os.path.join(base_dir,"Outputslogs")后半段斜杠请小心被识别为转义字符,所以请用/,因为windows都能识别到此路径。
    python中如何获取当前时间,并计算时间差
    Web UI自动化测试-滚动条操作
    java 基础 1.什么是Java?2.Java语言的特点?
    java 排序3 插入排序
    java 排序2 冒泡排序
  • 原文地址:https://www.cnblogs.com/stepping/p/7250525.html
Copyright © 2011-2022 走看看