2827704_ac_436ms_92k.cpp

来自「北大大牛代码 1240道题的原代码 超级权威」· C++ 代码 · 共 60 行

CPP
60
字号
#include <stdio.h>
#include <algorithm>
#include <cassert>

using namespace std;

int n;
struct node
{
	int x, y;
}pot[2001];

int cmp(const void *a,const void *b)
{
	node *aa = (node *)a;
	node *bb = (node *)b;
	if(aa->x == bb->x)
		return bb->y - aa->y;
	else
		return aa->x - bb->x;
}

int main()
{
	int x1, x2, y1, y2;
	int i, j;
	node tmp;
	int ans;

	while(scanf("%d",&n)==1)
	{
		ans = 0;
		for(i = 0; i < n; i++)
			scanf("%d%d",&pot[i].x,&pot[i].y);
		qsort(pot,n,sizeof(pot[0]),cmp);
		for(i = 0; i < n; i++)
			for(j = i+1; j < n; j++)
			{
				x1 = pot[i].x;y1 = pot[i].y;
				x2 = pot[j].x;y2 = pot[j].y;
				if((x1+x2+y2-y1)%2||(y1+y2+x1-x2)%2)
					continue;
				tmp.x = (x1+x2+y2-y1)/2;
				tmp.y = (y1+y2+x1-x2)/2;
				if(bsearch((const void *)(&tmp),pot,n,sizeof(pot[0]),cmp)==NULL)
					continue;
				if((x1+x2+y1-y2)%2||(y1+y2+x2-x1)%2)
					continue;
				tmp.x = (x1+x2+y1-y2)/2;
				tmp.y = (y1+y2+x2-x1)/2;
				if(bsearch((const void *)(&tmp),pot,n,sizeof(pot[0]),cmp)==NULL)
					continue;
				ans++;
			}
		assert(ans%2==0);
		printf("%d\n",ans/2);
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?