“劝退赛第二场”
# HDU 6055 Regular polygon
题意:二维平面上给你一些整点(关键),求组成的正多边形个数。
分析:整点很关键,在平面上构成的正多边形只有正四边形(证明链接)。这样一来问题就简单很多啦,只需要枚举任意两个点,由此获得其他两个点然后判断能否在 INPUT 中找到。对于查找可以使用 set + count( ) / 二分查找,俱乐部有人用 map 却一直 TLE 。
代码如下:
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll N = 505;
struct node {
int x;
int y;
bool operator<(const node a) const {
if(x == a.x)return y < a.y;
else return x < a.x;
}
} a[N];
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
while(cin>>n){
int ans=0;
set<node> ss;
for(int i=0;i<n;i++){
cin>>a[i].x>>a[i].y;
ss.insert(node{a[i].x,a[i].y});
}
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++){
int x1,y1,x2,y2;
x1 = a[i].x + (a[i].y - a[j].y);
y1 = a[i].y - (a[i].x - a[j].x);
x2 = a[j].x + (a[i].y - a[j].y);
y2 = a[j].y - (a[i].x - a[j].x);
if(ss.count(node{x1,y1}) && ss.count(node{x2,y2}))
ans++;
x1 = a[i].x - (a[i].y - a[j].y);
y1 = a[i].y + (a[i].x - a[j].x);
x2 = a[j].x - (a[i].y - a[j].y);
y2 = a[j].y + (a[i].x - a[j].x);
if(ss.count(node{x1,y1}) && ss.count(node{x2,y2}))
ans++;
}
}
cout<< ans/4 <<endl;
}
return 0;
}
JNU ACM ICPC
WYC