Easy Fruit NinjaTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 531 Accepted Submission(s): 137
Problem Description
YY is a clever boy . Recently he bought a new mobile phone .he is addicted in a game named Fruit Ninja . In the game . The fruit will fly from the bottom of the screen in a parabolic curve(g = 10.0 m/s^2). Your aim is cutting the fruit before the fruit fall down and disappear but you can't cut it at time 0.0 . And YY is a lazy boy. He just want to cut the fruit use the least times . Every time he cut .all the fruit in the same line will be cut. To simple this problem .we regard the fruit as a point . The mobile phone is a Two dimensional coordinate department There are only three Fruit fly into the air. YY want to know if exist a time that three fruit are in a same line and what the time it is.
Input
In the first line . Only a number T (1 <= T <= 1000) indicate the test case
each test case the first line contain three real number x1, x2, x3, indicate the coordinate of the fruit (x1, 0) (x2, 0), (x3, 0) ( - 10000 <= x1, x2, x3 <= 10000) the second line contain three real number v1, v2, v3, indicate the speed of the fruit (0 <= v1, v2, v3 <= 10000) the third line contain three real number a, b, c, indicate the radian of the fruit's direction to the x coordinate ( 0 <= a, b, c <= pi )
Output
For each case , output the number of case and the time (round to 4 decimal places), if there are more than one solution , just output "Multiply answer", if there is no answer ,
just output “-1”, .(as shown in the sample output)
Sample Input
Sample Output
Author
mhl
Source
|
解题思路:求出每个水果的运动轨迹然后利用叉积共线列方程求出时间t即可
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#define eps 1e-8
using namespace std;
struct Node{
double x,v,r;
double vx,vy;
}A[3];
double MIN(double a,double b){
return a<b?a:b;
}
int sig(double n){
if(fabs(n)<eps)return 0;
else if(n<0)return -1;
return 1;
}
int main()
{
int t,i,j,k=1;
scanf("%d",&t);
while(t--){
for(i=0;i<3;++i){
scanf("%lf",&A[i].x);
}
for(i=0;i<3;++i){
scanf("%lf",&A[i].v);
}
for(i=0;i<3;++i){
scanf("%lf",&A[i].r);
A[i].vx=A[i].v*cos(A[i].r);
A[i].vy=A[i].v*sin(A[i].r);
}
double tmin=MIN(A[0].vy/5.0,MIN(A[1].vy/5.0,A[2].vy/5.0));
double t1=(A[0].vx-A[1].vx)*(A[1].vy-A[2].vy)-(A[0].vy-A[1].vy)*(A[1].vx-A[2].vx);
double t2=(A[0].x-A[1].x)*(A[1].vy-A[2].vy)-(A[1].x-A[2].x)*(A[0].vy-A[1].vy);
printf("Case #%d: ",k++);
if(sig(tmin)<=0)printf("-1\n");
else if(sig(t1)==0&&sig(t2)==0){
printf("Multiply answer\n");
}
else if(sig(t1)==0)printf("-1\n");
else {
double ans=-t2/t1;
if(sig(ans)>=0&&sig(tmin-ans)>=0)
printf("%.4f\n",ans);
else printf("-1\n");
}
}
return 0;
}