codeforces 33D Knights

题目链接

D. Knights
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Berland is facing dark times again. The army of evil lord Van de Mart is going to conquer the whole kingdom. To the council of war called by the Berland's king Valery the Severe came n knights. After long discussions it became clear that the kingdom has exactly n control points (if the enemy conquers at least one of these points, the war is lost) and each knight will occupy one of these points.

Berland is divided into m + 1 regions with m fences, and the only way to get from one region to another is to climb over the fence. Each fence is a circle on a plane, no two fences have common points, and no control point is on the fence. You are given k pairs of numbers aibi. For each pair you have to find out: how many fences a knight from control point with index ai has to climb over to reach control point bi(in case when Van de Mart attacks control point bi first). As each knight rides a horse (it is very difficult to throw a horse over a fence), you are to find out for each pair the minimum amount of fences to climb over.

Input

The first input line contains three integers nmk (1 ≤ n, m ≤ 10000 ≤ k ≤ 100000). Then follow n lines, each containing two integers KxiKyi ( - 109 ≤ Kxi, Kyi ≤ 109) — coordinates of control point with index i. Control points can coincide.

Each of the following m lines describes fence with index i with three integers riCxiCyi (1 ≤ ri ≤ 109 - 109 ≤ Cxi, Cyi ≤ 109) — radius and center of the circle where the corresponding fence is situated.

Then follow k pairs of integers aibi (1 ≤ ai, bi ≤ n), each in a separate line — requests that you have to answer. ai and bi can coincide.

Output

Output exactly k lines, each containing one integer — the answer to the corresponding request.


题解:
打表,每个点跟每个圆的位置关系,如果两点同在圆外或同在圆内,
则不需要跨过栅栏,否则需要跨过。
代码:

#include<cstdio>
#include<string.h>
#include<cmath>
using namespace std;
#define ll long long 
const long long maxn=2007;
long long x1[maxn],y11[maxn],x2[maxn],y2[maxn],r[maxn];
long long num[maxn][maxn];
int main()
{
	long long n,m,k;scanf("%lld%lld%lld",&n,&m,&k);
	for(long long i=1;i<=n;i++)
		scanf("%lld%lld",&x1[i],&y11[i]);
	for(long long i=1;i<=m;i++)
		scanf("%lld%lld%lld",&r[i],&x2[i],&y2[i]);
	memset(num,0,sizeof(num));
	for(long long i=1;i<=n;i++)
	{
		for(long long j=1;j<=m;j++)
		{
			long long d=(x1[i]-x2[j])*(x1[i]-x2[j])+(y11[i]-y2[j])*(y11[i]-y2[j]);
			if(d<r[j]*r[j]) 
				num[i][j]=1;
		}               
	}
	while(k--)
	{
		long long a,b;scanf("%lld%lld",&a,&b);long long sum=0;
		for(long long i=1;i<=m;i++)
			if(num[a][i]!=num[b][i])sum++;
		printf("%lld\n",sum);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值