zoukankan      html  css  js  c++  java
  • hdu 5365 判断正方形

    题意:给出n个点(坐标均为整数),判断可以构成多少个正三角形、正四边形、正五边形、正六边形。

    官方题解:地球人都知道整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可。假如你不是地球人,那么即使暴力枚举正三边形和稍微不那么暴力地找正五边形和正六边形也是可以通过的(反正找不到)。

    ......看来我不是地球人......

    至于判断正方形,只要判断四边相等和一条对角线是边长的根号2倍就行了。

     1 #include <iostream>
     2 #include <cstring>
     3 #include <cstdio>
     4 using namespace std;
     5 
     6 const int N = 20;
     7 
     8 struct Point 
     9 {
    10     int x, y;
    11 } point[N];
    12 
    13 int square( int x )
    14 {
    15     return x * x;
    16 }
    17 
    18 int dis2( int a, int b )
    19 {
    20     return square( point[a].x - point[b].x ) + square( point[a].y - point[b].y );
    21 }
    22 
    23 int judge( int a, int b, int c, int d )
    24 {
    25     int dd = dis2( a, c );
    26     if ( dis2( a, b ) * 2 == dd && dis2( b, c ) * 2 == dd
    27       && dis2( c, d ) * 2 == dd && dis2( d, a ) * 2 == dd ) return 1;
    28     return 0;
    29 }
    30 
    31 int main ()
    32 {
    33     int n;
    34     while ( scanf("%d", &n) != EOF )
    35     {
    36         for ( int i = 0; i < n; i++ )
    37         {
    38             scanf("%d%d", &point[i].x, &point[i].y);
    39         }
    40         int ans = 0;
    41         for ( int i = 0; i < n; i++ )
    42         {
    43             for ( int j = 0; j < n; j++ )
    44             {
    45                 if ( i == j ) continue;
    46                 for ( int k = 0; k < n; k++ )
    47                 {
    48                     if ( i == k || j == k ) continue;
    49                     for ( int l = 0; l < n; l++ )
    50                     {
    51                         if ( i == l || j == l || k == l ) continue;
    52                         ans += judge( i, j, k, l );
    53                     }
    54                 }
    55             }
    56         }
    57         ans >>= 3;
    58         printf("%d
    ", ans);
    59     }
    60     return 0;
    61 }
  • 相关阅读:
    20200924-5 四则运算试题生成,结对
    20200924-4 代码规范,结对要求
    20200929-git地址
    20200917-1 每周例行报告
    20200917-3白名单
    20200917-2 词频统计
    20200910-1 每周例行报告
    20200910-2 博客作业
    20200924-3 单元测试,结对
    20200924-5 四则运算试题生成,结对
  • 原文地址:https://www.cnblogs.com/huoxiayu/p/4714733.html
Copyright © 2011-2022 走看看