uva10310

题目大意:

 

一只老鼠和一条狗,地上有n个洞。现在给出老鼠和狗的初始位置,老鼠朝准一个洞跑去,狗以2倍的速度跑过去,看看能不能追上,如果狗先到,那么就吃掉它,如果鼠先到,那么就逃了。

 

求出第一个鼠能逃脱的洞的位置,如果不能逃,那么就被吃掉。

 

这个题目直接枚举所有洞就行了,注意是2倍的鼠的距离小于等于狗的距离。同时到达不会被吃掉,这个地方wa了一次。

 

代码:

#include <iostream>
#include<cstdio>
#include <cstdlib>
#include<cmath>
using namespace std;

const int MaxN = 1010;
int n;

struct POINT
{
	double x,y;
}point[MaxN];
struct POINT pDog,pMouse;
double GetDis(POINT p1, POINT p2)
{
	return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));
}

int main()
{
	while (scanf("%d %lf %lf %lf %lf", &n, &pMouse.x, &pMouse.y, &pDog.x, &pDog.y) != EOF)
	{
		int flag = 1;
		for (int i = 0; i < n;  ++ i)
		{
			scanf("%lf %lf", &point[i].x, &point[i].y);
		}
		for (int i = 0; i < n; ++ i)
		{
			double s1 =2.0 * GetDis(pMouse, point[i]);
			double s2 = GetDis(pDog, point[i]);
			if ( s1 <= s2)
			{
				flag = 0;
				printf("The gopher can escape through the hole at (%.3lf,%.3lf).\n", point[i].x, point[i].y);
				break;
			}
		}
		if (flag)
		{
			printf("The gopher cannot escape.\n");
		}
	}
	return 0;
}


 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值