您的位置:首页 > 编程语言 > Go语言

HDU 6055 Regular polygon (暴力)

2017-07-27 18:39 323 查看
题意,二维平面上给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;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: