HDU 4024 Dwarven Sniper’s hunting (计算几何-其它,搜索-二分)

Dwarven Sniper’s hunting

Problem Description

Now the hunting starts in the world named DOTA, a stupid PC game which cannot play with others together.

Among the individuals in the game, there are two heroes named Dwarven Sniper and Lycanthrope. Lycanthrope wants to escape from being captured; however, our Dwarven Sniper won’t let him go! He will use the Silver Bullet to kill the Lycanthrope by only one shot!
Yes, that’s enough.

Lycanthrope is running on a line in the map with a constant speed and direction. The weapon range of the Silver Bullet is limited by L meters. Dwarven Sniper can run for a while freely, and then shoot Lycanthrope. In order to show his excellent shooting skill,
Dwarven Sniper wants the Silver Bullet flying as far as possible. But don’t forget the flying time of the Silver Bullet due to considerable weight of the bullet. And Dwarven Sniper wants to stop the hunting as quickly as possible. So if there is more than
one way to show his excellent skill, he would choose the fastest way. In this problem we consider the Silver Bullet and Lycanthrope as two points.

Now Dwarven Sniper wants to know the maximum length that the Silver Bullet can fly, and the shortest time that the hunting lasts. Specifically, the total hunting time is defined as the time interval from the start of hunting to the moment that the bullet hit
Lycanthrope. Can you help him?

Input

There are several test cases. Each of them contains only one line which consist of 9 real numbers, that are X1, Y1, X2, Y2, Lx, Ly, vD , vB and L (-10000 <= X1 , Y1 , X2 , Y2 , Lx , Ly <= 10000 , 0 <= vD , vB , L <=100000).

The pair (X1, Y1) is the starting position of the Lycanthrope while (X2, Y2) is the starting position of Dwarven Sniper.

(Lx, Ly) is the moving vector per second of the Lycanthrope.

vD is the speed of the Dwarven Sniper .

vB is the speed of the Silver Bullet.

All units are meters/second.

It is guaranteed that (Lx*Lx+Ly*Ly) < vD*vD < vB*vB , and Dwarven Sniper’s starting position is different from Lycanthrope’s position. The input ends with a line containing all zeros.

Output

For each test case, output two real numbers S and T in a line separated by a single space denoting that the Silver bullet flies S meters before hitting Lycanthrope and the hunting lasts for T seconds, both with 3 digits after the decimal point.

You may assume that Dwarven Sniper can finish his hunting within no more than 1e+9 seconds.

Sample Input

-1 0 0 10 1 0 2 10 10
0 0 0 5 0 1 2 6 6
0 0 0 0 0 0 0 0 0

Sample Output

10.000 1.000
6.000 3.000

Source

The
36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest

Recommend

lcy   |   We have carefully selected several similar problems for you:  4022 4021 4023 4025 4030

题目大意:

D追杀L,D是一个远程英雄,D可以发出距离为L的技能,已知L这个英雄的起始位置为X1,Y1,移动速度方向矢量是LX,LY,D的起始位置为X2,Y2,D的移动速度是VD,D发出L距离的弓箭的移动速度是VB,(Lx*Lx+Ly*Ly) < vD*vD < vB*vB,问你在D充分表现自己射击能力的情况下,最少多长时间杀死L?

解题思路:

因为:(Lx*Lx+Ly*Ly) < vD*vD < vB*vB,也就是说:L的移动速度<D的移动速度<弓箭的移动速度。也就是D表现自己的能力的话,一定射击的最长距离为L,那么时间怎么算,可以二分出答案。

解题代码:

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

// X1, Y1, X2, Y2, Lx, Ly, vD , vB and L

const double eps=1e-7;
double X1,Y1,X2,Y2,lx,ly,vd,vb,L;

double getdis(double ax,double ay,double bx,double by){
    return sqrt ( (ax-bx)*(ax-bx)+(ay-by)*(ay-by) );
}

double getmin(double ans1,double ans2){
    if(ans1<-eps) return ans2;
    if(ans2<-eps) return ans1;
    return min(ans1,ans2);
}

void solve(){
    double l=L/vb,r=1e9;
    while(r-l>eps){
        double mid=(l+r)/2;
        double X0=X1+mid*lx,Y0=Y1+mid*ly;
        double dis0=getdis(X0,Y0,X2,Y2);
        double disd=vd*(mid-L/vb);
        if(dis0<=L){
            if(disd+dis0<=L) l=mid;
            else r=mid;
        }else{
            if(disd+L>=dis0) r=mid;
            else l=mid;
        }
    }
    printf("%.3lf %.3lf\n",L,(r+l)/2);
}

int main(){
    while(cin>>X1>>Y1>>X2>>Y2>>lx>>ly>>vd>>vb>>L){
        if( fabs(X1)<eps && fabs(X2)<eps && fabs(Y1)<eps && fabs(Y2)<eps ){
            if( fabs(lx)<eps && fabs(ly)<eps && fabs(vd)<eps && fabs(vb)<eps && fabs(L)<eps ) break;
        }
        solve();
    }
    return 0;
}

HDU 4024 Dwarven Sniper’s hunting (计算几何-其它,搜索-二分)

时间: 2024-08-12 11:30:19

HDU 4024 Dwarven Sniper’s hunting (计算几何-其它,搜索-二分)的相关文章

hdu 4024 二分

转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度都很快,充分体会到二分的效率之高啊~~~ 题目中一个很重要的条件就是 (Lx*Lx+Ly*Ly) < vD*vD < vB*vB , 这样说明一定是可以追上的,而且可以以最大的距离射中,所以第一问的答案一定就是L的. 假设追击者跑的时间是 t1,那么肯定子弹飞行时间就是 L/vB 了 那么此时被追击者

HDU 1798 Tell me the area (计算几何)

Tell me the area Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1801    Accepted Submission(s): 542 Problem Description There are two circles in the plane (shown in the below picture), there is

HDU 5024 Wang Xifeng&#39;s Little Plot (搜索)

Wang Xifeng's Little Plot Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 157    Accepted Submission(s): 105 Problem Description <Dream of the Red Chamber>(also <The Story of the Stone>)

HDU 4004 The Frog&#39;s Games(基本算法-贪心,搜索-二分)

The Frog's Games Problem Description The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over the river. The

HDU 3699 A hard Aoshu Problem (暴力搜索)

题意:题意:给你3个字符串s1,s2,s3;要求对三个字符串中的字符赋值(相同的字符串进行相同的数字替换), 替换后的三个数进行四则运算要满足左边等于右边,求有几种解法. Sample Input 2 A A A BCD BCD B Sample Output 5 72 eg:ABBDE   ABCCC   BDBDE :令 A = 1, B = 2, C = 0, D = 4, E = 5 12245 + 12000 = 24245: 注意没有前导零!! #include<stdio.h>

HDU 4960 Another OCD Patient(记忆化搜索)

HDU 4960 Another OCD Patient 题目链接 记忆化搜索,由于每个碎片值都是正数,所以每个前缀和后缀都是递增的,就可以利用twopointer去找到每个相等的位置,然后下一个区间相当于一个子问题,用记忆化搜索即可,复杂度接近O(n^2) 代码: #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int INF = 0x3f3f3f

hdu 2485 Destroying the bus stations 迭代加深搜索

求最少去掉几个公交站使得从s到t的最短路径大于k. 迭代加深搜索. #include <cstdio> #include <cstring> #include <queue> using namespace std; #define maxn 60 #define maxm 50000 int n,m,K,cnt,up; int head[maxn],pre[maxn]; int road[maxn][maxn]; bool del[maxn]; queue<in

【HDU 1839】 Delay Constrained Maximum Capacity Path(二分+最短路)

[HDU 1839] Delay Constrained Maximum Capacity Path(二分+最短路) Delay Constrained Maximum Capacity Path Time Limit: 10000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 1515    Accepted Submission(s): 481 Problem

HDU 3036 Escape 网格图多人逃生 网络流||二分匹配 建图技巧

前言 在编程过程中总结归纳出来的一种编程经验,从而形成的设计思想称为设计模式. 设计模式有23种.它适用于所有的编程语言. 常用的有创新型的设计模式:简单工厂.抽象工厂和单例模式:行为型的设计模式:模板设计模式.观察者模式和命令模式:结构性的设计模式:适配器设计模式.代理模式(静态和动态两种,典型的有在spring的AOP编程中使用)和装饰器设计模式. 正文 单例模式(singleton) 保证一个类在内存中只能创建一个实例. 1.实现步骤: 1)将构造器私有化,即使用private修饰构造器