题目链接
http://acm.hdu.edu.cn/showproblem.php?pid=2701
题意 有一个萤火虫会闪现 一个人 也会闪现 给出 这个人的起始位置 和他能够闪现的距离 然后依次给出萤火虫的坐标 这个人 每次都往萤火虫的坐标闪现 如果 这个人能够到达的距离方圆1个单位长度以内 萤火虫在里面 那么这个人就能够抓住萤火虫 就输出坐标 如果最后都没有抓住 那么 就是抓不住了
思路
只要模拟一下就好了
求这个人每次移动的坐标 学长点了我一下,,竟然是用相似三角形。。初中的东西啊。。
AC代码
#include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <cmath> #include <climits> #include <ctime> #include <iostream> #include <algorithm> #include <deque> #include <vector> #include <queue> #include <string> #include <map> #include <stack> #include <set> #include <list> #include <numeric> #include <sstream> #include <iomanip> #include <limits> #define CLR(a, b) memset(a, (b), sizeof(a)) #define pb push_back using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; typedef pair <int, int> pii; typedef pair <ll, ll> pll; typedef pair<string, int> psi; typedef pair<string, string> pss; const double PI = acos(-1.0); const double E = exp(1.0); const double eps = 1e-8; const int INF = 0x3f3f3f3f; const int maxn = 1e6 + 5; const int MOD = 1e9; double getdis(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { double n, x, y; int t = 1; while (scanf("%lf%lf%lf", &n, &x, &y) && (n || x || y)) { double a, b; int flag = 1; while (scanf("%lf%lf", &a, &b) && (a != -1 || b != -1)) { if (flag) { double dis = getdis(x, y, a, b); if (dis <= n + 1.0) { printf("Firefly %d caught at (%.0lf,%.0lf)\n", t++, a, b); flag = 0; } x += (a - x) * n / dis; y += (b - y) * n / dis; } } if (flag) printf("Firefly %d not caught\n", t++); } }转载于:https://www.cnblogs.com/Dup4/p/9433098.html