hdoj3975Easy Fruit Ninja



Easy Fruit Ninja

Time 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
      
      
3 150 35 250 80 200 220 2.00 2.17 2.27 0 1 2 1 1 1 1 1 1 0 0 0 1 2 3 1 1 1
 

Sample Output
      
      
Case #1: 8.4151 Case #2: Multiply answer Case #3: Multiply answer
 

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;
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值