UVa 10310 - Dog and Gopher

题目:有一只狗和一只地鼠,n个地鼠洞,狗的奔跑速度是地鼠的二倍,问是否存在地鼠能逃跑的洞。

分析:简单题。枚举所有的洞判断即可。

说明:注意精度,不适用开根号直接利用平方比较即可。

#include <iostream>
#include <cstdlib>
#include <cstdio>

using namespace std;

typedef struct pnode
{
	double x,y;
}point; 
point H[1005],D,G;

double dist( point a, point b )
{
	return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}

int main()
{
	int n;
	while ( ~scanf("%d",&n) ) {
		scanf("%lf%lf%lf%lf",&G.x,&G.y,&D.x,&D.y);
		for ( int i = 0 ; i < n ; ++ i )
			scanf("%lf%lf",&H[i].x,&H[i].y);
		
		int flag = 1;
		for ( int i = 0 ; i < n ; ++ i )
			if ( 4.0*dist( G, H[i] ) <= dist( D, H[i] ) ) {
				printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n",H[i].x,H[i].y);
				flag = 0;break;
			}
		if ( flag ) printf("The gopher cannot escape.\n");
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值