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

📄 pku2002.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>

typedef struct 
{
	int x, y;
} Point;

Point p[1000];

int cmp(const void *a, const void *b)
{
	Point *aa = (Point *)a;
	Point *bb = (Point *)b;

	if (aa->x != bb->x)
	{
		return aa->x - bb->x;
	}
	else
	{
		return aa->y - bb->y;
	}
}

int main()
{
	int n, i, j, sum;
	Point t1, t2, *pp;

	while (scanf("%d", &n) != -1 && n > 0)
	{
		for (i = 0; i < n; i++)
		{
			scanf("%d %d", &p[i].x, &p[i].y);
		}
		qsort(p, n, sizeof(p[0]), cmp);

		for (i = 0, sum = 0; i < n; i++)
		{
			for (j = i + 1; j < n; j++)
			{
				if ((p[i].x + p[i].y + p[j].x + p[j].y) %2 != 0) continue;
				t1.x = (p[i].x + p[j].x + p[i].y - p[j].y) / 2;
				t1.y = (p[i].y + p[j].y - p[i].x + p[j].x) / 2;
				t2.x = (p[i].x + p[j].x - p[i].y + p[j].y) / 2;
				t2.y = (p[i].y + p[j].y + p[i].x - p[j].x) / 2;

				pp = (Point *)bsearch(&t1, p, n, sizeof(p[0]), cmp);
				if (pp == NULL) continue;
				pp = (Point *)bsearch(&t2, p, n, sizeof(p[0]), cmp);
				if (pp == NULL) continue;
				else sum++;
			}
		}
		printf("%d\n", sum / 2);
	}
	return 0;
}

⌨️ 快捷键说明

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