zoukankan      html  css  js  c++  java
  • 2017 Multi-University Training Contest

    Regular polygon

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

    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
    题意:给你n个整数点 问你组成正多边形的有几组
    因为题目给的是整数点 只要正四边形才能是整点
    所以我们只要枚举其中任意两个点 利用旋转公式可以得到其它两个点 判断其他两个点是否存在就可以了
    旋转公式是 x=xcos@-ysin@
              y=xsin@-ycos@;
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<algorithm>
     4 #include<cstring>
     5 #include<cstdlib>
     6 #include<string.h>
     7 #include<set>
     8 #include<vector>
     9 #include<queue>
    10 #include<stack>
    11 #include<map>
    12 #include<cmath>
    13 typedef long long ll;
    14 typedef unsigned long long LL;
    15 using namespace std;
    16 const double PI=acos(-1.0);
    17 const double eps=0.0000000001;
    18 const int N=1000+100;
    19 struct node{
    20     int x,y;
    21 }a[N];
    22 int vis[N][N];
    23 int main(){
    24     int n;
    25     while(scanf("%d",&n)!=EOF){
    26         memset(vis,0,sizeof(vis));
    27         for(int i=1;i<=n;i++){
    28             scanf("%d%d",&a[i].x,&a[i].y);
    29             vis[a[i].x+500][a[i].y+500]=i;
    30         }
    31         ll ans=0;
    32         int x,y;
    33         int xx,yy;
    34         int len;
    35         for(int i=1;i<=n;i++){
    36             for(int j=i+1;j<=n;j++){
    37                 if(i==j)continue;
    38                 x=(a[j].y-a[i].y)+a[i].x;
    39                 y=(a[j].x-a[i].x)*(-1)+a[i].y;
    40                 xx=-(a[i].y-a[j].y)+a[j].x;
    41                 yy=(a[i].x-a[j].x)+a[j].y;
    42                 int t1=vis[x+500][y+500];
    43                 int t2=vis[xx+500][yy+500];
    44                 if(t1&&t2)ans++;
    45                 x=-(a[j].y-a[i].y)+a[i].x;
    46                 y=(a[j].x-a[i].x)+a[i].y;
    47                 xx=(a[i].y-a[j].y)+a[j].x;
    48                 yy=-(a[i].x-a[j].x)+a[j].y;
    49                 int t3=vis[x+500][y+500];
    50                 int t4=vis[xx+500][yy+500];
    51                 if(t3&&t4)ans++;
    52             }
    53         }
    54        // cout<<ans<<endl;
    55         ans=ans/4;
    56         printf("%I64d
    ",ans);
    57     }
    58 }
  • 相关阅读:
    HUST 1017 Exact cover (Dancing links)
    HDU 1160 FatMouse's Speed (DP)
    HDU 1058 Humble Numbers (DP)
    Kubernetes(k8s)
    linux命令
    入侵检测系统
    lynis检测
    CPU死锁
    检测工具lynis
    Linux表面工作
  • 原文地址:https://www.cnblogs.com/Aa1039510121/p/7257530.html
Copyright © 2011-2022 走看看