F. Friends(2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest )

F. Friends
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Three friends Alex, Dmitry and Petr want to go abroad for a better life. They start at 09:00 in the morning in their home city A and want to be in the foreign city B as soon as possible.

Alex wants to start immediately and decided to use a car and a highway. He has to drive directly to the customs point C, then spends Dminutes there to pass the customs, and then drives directly to the city B. He drives the car with a speed of V kilometers per hour.

Dmitry has bought an airplane ticket. His plane departs at time T from the city A and flies for some time F directly to the city B.

Petr felt adventurous, so he decided to take his neighbor's tractor and drive straight to the city B with a speed of W kilometers per hour. If Petr's path lies through the customs point C, he spends D minutes there to pass the customs too. Otherwise, he does not stop during the whole trip.

Now they wonder who will be the first in the city B and can cook a welcoming dinner for all of them. We assume that friends live on a plane, and the distance between points is the common Euclidean distance.

Input

The first line of input contains six integers XAYAXBYBXC and YC, the coordinates in kilometers of cities A and B and the customs point C respectively (0 ≤ XA, YA, XB, YB, XC, YC ≤ 1000). It is guaranteed that the customs point C is closer to A than the city B and closer to B than the city A.

The second line contains two integers D and V, the time to pass the customs in minutes and the speed of Alex's car in kilometers per hour respectively (0 ≤ D ≤ 100040 ≤ V ≤ 100).

The third line contains the departure time T and the duration F of Dmitry's flight, both in the format "HH:MM". It is guaranteed that the departure time is correct, later than 09:00 and earlier than 24:00. The flight duration is greater than 00:00 and less than 24:00.

The fourth line contains one integer W, the speed of Petr's tractor in kilometers per hour (10 ≤ W ≤ 50).

Output

Output the name of the first friend in the city B. It is guaranteed that the absolute difference between arrival times for each pair of friends will be at least one second.

Sample test(s)
input
0 0 10 0 5 5
60 100
10:00 00:05
10
output
Petr
input
0 0 100 0 50 50
0 100
09:01 02:10
50
output
Alex
input
0 0 1000 0 500 500
0 100
10:00 02:10
33
output
Dmitry


模拟,三个人分别算一下,比较一下就行了,C点是否在A,B之间的判断用斜率相等,即(y3-y1)/(x3-x1)==(y2-y1)/(x2-x1)整理得(y3-y1)*(x2-x1)==(y2-y1)*(x3-x1)


代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const double eps=1e-6;
int main()
{
    int x1,y1,x2,y2,x3,y3;
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3))
    {
        int d,v,h1,m1,h2,m2,w;
        scanf("%d%d",&d,&v);
        scanf("%d:%d%d:%d",&h1,&m1,&h2,&m2);
        scanf("%d",&w);
        double t1,t2,t3;
        double dis1,dis2,dis3;
        dis1=sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
        dis2=sqrt((y3-y1)*(y3-y1)+(x3-x1)*(x3-x1));
        dis3=sqrt((y3-y2)*(y3-y2)+(x3-x2)*(x3-x2));
        t1=d*1.0/60+(dis2+dis3)*1.0/v;
        if((y3-y1)*(x2-x1)==(y2-y1)*(x3-x1))
        {
            t3=d*1.0/60+dis1/w;
        }
        else
        {
            t3=dis1/w;
        }
        h2=h1+h2;
        m2=m1+m2;
        t2=(h2-9)+(m2)*1.0/60;
        if(t1<t2&&t1<t3)
        printf("Alex\n");
        if(t2<t1&&t2<t3)
        printf("Dmitry\n");
        if(t3<t1&&t3<t2)
        printf("Petr\n");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值