// Dog and Gopher (狗拿地鼠)
// PC/UVa IDs: 111301/10310, Popularity: A, Success rate: average Level: 1
// Verdict: Accepted
// Submission Date: 2011-11-01
// UVa Run Time: 0.044s
//
// 版权所有(C)2011,邱秋。metaphysis # yeah dot net
//
// [解题方法]
// 简单题,判断输入中那个洞与狗的距离大于与地鼠的距离两倍以上。
#include <iostream>
#include <cmath>
using namespace std;
int main(int ac, char *av[])
{
int n;
double gopherX, gopherY, dogX, dogY, holeX, holeY;
double emptyX, emptyY;
while (cin >> n >> gopherX >> gopherY >> dogX >> dogY)
{
bool successed = false;
for (int i = 1; i <= n; i++)
{
cin >> holeX >> holeY;
// 判断距离。
if ((pow(dogX - holeX, 2) + pow(dogY - holeY, 2)) >=
4.0 * (pow(gopherX - holeX, 2) +
pow(gopherY - holeY, 2)))
{
successed = true;
// 读取完剩余数据。
for (int j = i + 1; j <= n; j++)
cin >> emptyX >> emptyY;
break;
}
}
if (successed)
{
cout.precision(3);
cout.setf(ios::fixed | ios::showpoint);
cout << "The gopher can escape through the hole at (";
cout << holeX << "," << holeY << ")." << endl;
}
else
cout << "The gopher cannot escape." << endl;
}
return 0;
}UVa Problem 10310 Dog and Gopher (狗拿地鼠)
最新推荐文章于 2019-06-27 22:23:57 发布
本文提供了一种解决「Dog and Gopher」问题的方法,该问题是关于判断狗是否能成功抓到地鼠的问题。通过计算狗与地鼠、狗与洞之间的距离,找出一个洞与狗的距离大于与地鼠距离两倍以上的解决方案。
&spm=1001.2101.3001.5002&articleId=6950522&d=1&t=3&u=7659f867c62c4ffc9ceafad0ef34e986)
261

被折叠的 条评论
为什么被折叠?



