Crazy Tank
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6045 Accepted Submission(s): 1316
Problem Description
Crazy Tank was a famous game about ten years ago. Every child liked it. Time flies, children grow up, but the memory of happy childhood will never go.
Now you’re controlling the tank Laotu on a platform which is H meters above the ground. Laotu is so old that you can only choose a shoot angle(all the angle is available) before game start and then any adjusting is
not allowed. You need to launch N cannonballs and you know that the i-th cannonball’s initial speed is Vi.
On the right side of Laotu There is an enemy tank on the ground with coordination(L1, R1) and a friendly tank with coordination(L2, R2). A cannonball is considered hitting enemy tank if it lands on the ground between [L1,R1] (two ends are included). As the same reason, it will be considered hitting friendly tank if it lands between [L2, R2]. Laotu's horizontal coordination is 0.
The goal of the game is to maximize the number of cannonballs which hit the enemy tank under the condition that no cannonball hits friendly tank.
The g equals to 9.8.
Input
There are multiple test case.
Each test case contains 3 lines.
The first line contains an integer N(0≤N≤200), indicating the number of cannonballs to be launched.
The second line contains 5 float number H(1≤H≤100000), L1, R1(0<L1<R1<100000) and L2, R2(0<L2<R2<100000). Indicating the height of the platform, the enemy tank coordinate and the friendly tank coordinate. Two tanks
may overlap.
The third line contains N float number. The i-th number indicates the initial speed of i-th cannonball.
The input ends with N=0.
Output
For each test case, you should output an integer in a single line which indicates the max number of cannonballs hit the enemy tank under the condition that no cannonball hits friendly tank.
Sample Input
2
10 10 15 30 35
10.0
20.0
2
10 35 40 2 30
10.0
20.0
0
Sample Output
1
0
Hint
In the first case one of the best choices is that shoot the cannonballs parallelly to the horizontal line, then the first
cannonball lands on 14.3 and the second lands on 28.6.
In the second there is no shoot angle to make any cannonball land between [35,40] on the condition that no
cannonball lands between [2,30].
Source
2012 Asia JinHua Regional Contest
题意:
在上图中,从左边的制高点那里开始发射,角度可以随意
角度一但定下来就不能再改变了,求不能打到友军,能打到敌军的最多的炮弹
题解:
枚举角度,将 pi 分解成 1000 份,当时分解成180份 贡献了好几次的WA
每次枚举的角度,计算是否可以打到敌军,并且不打到友军
一旦打到友军就停止计算这个角度下发射炮弹
然后计算最大的击中炮弹数
#include <stdio.h>
#include <string.h>
#include <math.h>
#define g 9.8
#define pi 3.1415926
double h,l1,r1,l2,r2;
int n;
double can[ 205 ];
int judge(double x,double v)
{
double tmp1,tmp2;
tmp2 = sqrt(4*v*v*v*v*cos(x)*cos(x)*sin(x)*sin(x)+8*h*g*v*v*sin(x)*sin(x));
tmp1 = (-2*cos(x)*sin(x)*v*v+tmp2)/(2*g);
if(tmp1<=r2&&tmp1>=l2)
return -1;
else if(tmp1<=r1&&tmp1>=l1)
return 1;
else
return 0;
}
int main()
{
//freopen("in.txt","r",stdin);
while(scanf("%d",&n),n)
{
scanf("%lf%lf%lf%lf%lf",&h,&l1,&r1,&l2,&r2);
for(int i = 1 ; i <= n ; i++ )
scanf("%lf",&can[ i ]);
double x = pi/1000;
int ans = 0;
for(double i = 0 ; i < pi ; i += x )
{
int tmp1 = 0;
for(int j = 1 ; j <= n ; j++ )
{
int tmp = judge(i,can[j]);
if(tmp == -1)
{
tmp1 = 0;
break;
}
if( tmp == 1 ) tmp1++;
}
if(tmp1>ans) ans = tmp1;
}
printf("%d\n",ans);
}
return 0;
}
转载请注明原文地址: https://ju.6miu.com/read-1312019.html