pku2859.cpp

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· C++ 代码 · 共 61 行

CPP
61
字号
#include <stdio.h>
#include <stdlib.h>
#define size 500010
typedef struct Point
{
	int x, y;
} Point;

Point p[size];
int N;
int Dx, Dy;

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

void Solve()
{
	int i, cnt;
	Point pn;
	scanf("%d %d", &Dx, &Dy);
	for (i = 0; i < N; i++)
	{
		scanf("%d %d", &p[i].x, &p[i].y);
	}
	qsort(p, N, sizeof(p[0]), cmp);
	cnt = 0;
	for (i = 0; i < N; i++)
	{
		pn.x = p[i].x + Dx;
		pn.y = p[i].y + Dy;
		if (NULL == (Point*)bsearch(&pn, p, N, sizeof(pn), cmp))
			continue;
		pn.x = p[i].x;
		pn.y = p[i].y + Dy;
		if (NULL == (Point*)bsearch(&pn, p, N, sizeof(pn), cmp))
			continue;
		pn.x = p[i].x + Dx;
		pn.y = p[i].y;
		if (NULL == (Point*)bsearch(&pn, p, N, sizeof(pn), cmp))
			continue;
		cnt++;
	}
	printf("%d\n", cnt);
}

int main()
{
	while (EOF != scanf("%d", &N))
		Solve();
	return 0;
}

⌨️ 快捷键说明

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