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.
The first line of input contains six integers XA, YA, XB, YB, XC 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 ≤ 1000, 40 ≤ 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 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.
0 0 10 0 5 5 60 100 10:00 00:05 10
Petr
0 0 100 0 50 50 0 100 09:01 02:10 50
Alex
0 0 1000 0 500 500 0 100 10:00 02:10 33
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;
}