您的位置:首页 > 大数据 > 人工智能

2017 Multi-University Training Contest 2 1011

2017-07-27 20:24 274 查看
题意:给你最多500个坐标,坐标都为整数,让你求有多少个不同的正多边形数。

思路:正多边形一定是正方形,正方形的话,枚举两个点,找出另外两个点是否存在,最后结果除以4就是答案。

#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <string.h>
#include <string>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#define LL long long
#define INF 0x3f3f3f3f
const int MAX_N = 5e2+10;
const LL mod = 1e9+7;
const double eps = 1e-6;
using namespace std;
struct Point
{
int x,y;
}a[MAX_N];
int have[MAX_N][MAX_N];
int check(Point p1,Point p2)
{
int dx = p1.x-p2.x;
int dy = p1.y-p2.y;
int ans = 0;
if(p1.x+dy <= 200&&p1.x+dy >= 0&&p1.y-dx >= 0&&p1.y-dx <= 200&&p2.x+dy <= 200&&p2.x+dy >= 0
&&p2.y-dx >= 0&&p2.y-dx <= 200&&have[p1.x+dy][p1.y-dx]&&have[p2.x+dy][p2.y-dx])
ans++;
if(p1.x-dy >= 0&&p1.x-dy <= 200&&p1.y+dx <= 200&&p1.y+dx >= 0&&p2.x-dy >= 0&&p2.x-dy <= 200
&&p2.y+dx <= 200&&p2.y+dx >= 0&&have[p1.x-dy][p1.y+dx]&&have[p2.x-dy][p2.y+dx])
ans++;
return ans;
}
int main()
{
int N;
while(scanf("%d",&N)!=EOF)
{
memset(have,0,sizeof(have));
for(int i = 0;i < N;i++)
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].x+=100; a[i].y+=100;
have[a[i].x][a[i].y] = 1;
}
int ans = 0;
for(int i = 0;i < N;i++)
for(int j = i+1;j < N;j++)
ans+=check(a[i],a[j]);
cout<<ans/4<<endl;
}
return 0;
}
/*
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐