poj2002

#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct Node
{
short x;
short y;
struct Node *next;
}Node;


Node *Hash[57][57] = {0};




void addNode(Node n);
int nodeValid(Node n);


int nodeValid(Node n)
{
Node *p;
int xhash = n.x;
int yhash = n.y;


xhash = (xhash<0 ? -xhash : xhash)%57;
yhash = (yhash<0 ? -yhash : yhash)%57;


p = Hash[xhash][yhash];
while(p)
{
if(p->x==n.x && p->y==n.y)
return 1;
p = p->next;
}
return 0;
}
void addNode(Node n)
{
Node *t;
int xhash = n.x;
int yhash = n.y;


xhash = (xhash<0 ? -xhash : xhash)%57;
yhash = (yhash<0 ? -yhash : yhash)%57;


t = (Node *)malloc(sizeof(Node) * 1);
t->x = n.x;
t->y = n.y;


t->next = Hash[xhash][yhash];
Hash[xhash][yhash] = t;
}


int main(void)
{
int a,b;
int solution;
int i,j;
int n;
Node nodes[1000];
Node n3,n4;
scanf("%d",&n);
while(n)
{
memset(Hash,0,sizeof(Node *)*57*57);
solution = 0;
for(i=0; i<n; i++)
{
scanf("%d%d",&nodes[i].x,&nodes[i].y);
addNode(nodes[i]);
}
for(i=0; i<n-1; i++)
{
for(j=i+1; j<n; j++)
{
a = nodes[j].y-nodes[i].y;
b = nodes[j].x-nodes[i].x;
n3.x = nodes[i].x - (a);
n3.y = nodes[i].y + (b);
n4.x = nodes[j].x - (a);
n4.y = nodes[j].y + (b);
if( nodeValid(n3) && nodeValid(n4) )
solution++;
n3.x = nodes[i].x + (a);
n3.y = nodes[i].y - (b);
n4.x = nodes[j].x + (a);
n4.y = nodes[j].y - (b);
if( nodeValid(n3) && nodeValid(n4) )
solution++;
}
}
printf("%d\n",solution/4);
scanf("%d",&n);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值