标签:
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5365
题面:(严重吐槽,看着真不舒服,还是改一下吧)
4 0 0 0 1 1 0 1 1
1
#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;
struct point
{
int x,y;
}store[25];
//该位置是否有点标记
bool status[10][10];
//判断是否出界
bool inside(int x,int y)
{
if(x>=0&&x<9&&y>=0&&y<9)
return true;
else
return false;
}
int main()
{
int t,tx1,ty1,tx2,ty2,tx3,ty3,ans,xd,yd;
while(~scanf("%d",&t))
{
memset(status,0,sizeof(status));
ans=0;
for(int i=0;i<t;i++)
{
scanf("%d %d",&store[i].x,&store[i].y);
//标记
status[store[i].x][store[i].y]=1;
}
for(int i=0;i<t-1;i++)
{
for(int j=i+1;j<t;j++)
{
tx1=store[i].x;
tx2=store[j].x;
ty1=store[i].y;
ty2=store[j].y;
xd=tx1-tx2;
yd=ty1-ty2;
//所有点枚举
for(int k=0;k<=8;k++)
{
for(int m=0;m<=8;m++)
{
//该位置有点
if(status[k][m])
{
//且不是枚举的两个点
if((k==tx1&&m==ty1)||(k==tx2&&m==ty2))
continue;
//垂直
if((xd*(k-tx2)+yd*(m-ty2))==0)
{
//距离相等
if(((k-tx2)*(k-tx2)+(m-ty2)*(m-ty2))==(xd*xd+yd*yd))
{
tx3=k+xd;
ty3=m+yd;
//第四个点在界内,且存在
if(inside(tx3,ty3)&&status[tx3][ty3])
ans++;
}
}
}
}
}
}
}
//一个正方形四条边都会计算一次
ans/=4;
printf("%d\n",ans);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
BestCoder Round #50 (div.2) HDU 5365 Run(简单几何)
标签:
原文地址:http://blog.csdn.net/david_jett/article/details/47375659