HDU 6055 Regular polygon (暴力)

Posted dwtfukgv

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU 6055 Regular polygon (暴力)相关的知识,希望对你有一定的参考价值。

题意,二维平面上给N个整数点,问能构成多少个不同的正多边形。

析:容易得知只有正四边形可以使得所有的顶点为整数点。所以只要枚举两个点,然后去查找另外两个点就好。

代码如下:

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#define debug() puts("++++");
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const double inf = 0x3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 500 + 10;
const LL mod = 1e9 + 7;
const int dr[] = {-1, 0, 1, 0};
const int dc[] = {0, 1, 0, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c){
  return r > 0 && r <= n && c > 0 && c <= m;
}

map<P, int> mp;
P p[maxn];

P solve(const P &p1, const P &p2){
  int detx = p2.first - p1.first;
  int dety = p2.second - p1.second;
  return P(p1.first-dety, p1.second+detx);
}

int main(){
  while(scanf("%d", &n) == 1){
    mp.clear();
    for(int i = 0; i < n; ++i){
      scanf("%d %d", &p[i].first, &p[i].second);
      mp[p[i]] = true;
    }

    int ans = 0;
    for(int i = 0; i < n; ++i){
      for(int j = 0; j < n; ++j){
        if(i == j)  continue;
        P p1 = solve(p[i], p[j]);
        if(!mp.count(p1))  continue;
        P p2 = solve(p1, p[i]);
        if(!mp.count(p2))  continue;
        ++ans;
      }
    }
    printf("%d\n", ans/4);
  }
  return 0;
}

  

以上是关于HDU 6055 Regular polygon (暴力)的主要内容,如果未能解决你的问题,请参考以下文章

HDU 6055 Regular polygon (暴力)

2017多校训练2+计算几何+板HDU 6055 Regular polygon

hdu_6055 : Regular polygon (2017 多校第二场 1011) 计算几何

hdu6055 Regular polygon 脑洞几何 给定n个坐标(x,y)。x,y都是整数,求有多少个正多边形。因为点都是整数点,所以只可能是正四边形。

hdu 4033 Regular Polygon 计算几何 二分+余弦定理

hdu6055(求正方形个数)