⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 2795676_ac_2076ms_84k.cpp

📁 北大大牛代码 1240道题的原代码 超级权威
💻 CPP
字号:
#include <stdio.h>
#include <algorithm>
#include <cassert>

using namespace std;

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

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,n)
	{
		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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -