您的位置:首页 > 其它

HDU 2701 Lampyridae Teleportae

2015-08-06 10:56 363 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2701

题意:给出1个原点以及依次给出N个点,每一次都从原点向第i点移动L的距离,更新原点,移动后若i点在以原点为圆心半径为1的圆内,则符合条件,否则继续向下一个点进行移动直到符合条件

思路:题目依然很难读,到最后都没发现只要在1的范围内就满足条件,最后是原点的更新出了点问题,我一律按等比例进行更新……利用三角函数求出x和y的比列就好

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define esp 0.000000001
using namespace std;
int main()
{
int f,cas=0;
double x,y;
while (scanf("%d%lf%lf",&f,&x,&y)!=EOF)
{
if (fabs(x)<esp && fabs(y)<esp && fabs(f)<esp) break;
cas++;
int tx,ty,resx,resy,flag=0;
while (scanf("%d%d",&tx,&ty))
{
if (tx==-1 && ty==-1) break;
double dis=1.0*sqrt(1.0*(x-tx)*(x-tx)+1.0*(y-ty)*(y-ty));

if (dis<=f+1 && !flag)
{
resx=tx;
resy=ty;
flag=1;
}
double a=1.0*tx-x,b=1.0*ty-y;
x+=(a/dis*f);
y+=(b/dis*f);
}
if (flag==0) printf("Firefly %d not caught\n",cas);
else printf("Firefly %d caught at (%d,%d)\n",cas,resx,resy);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: