hdoj 4445 Crazy Tank 物理题/枚举角度1

Crazy Tank
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5033    Accepted Submission(s): 1017

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].

题意
就是告诉你,有个坐标在(0,h)的炮台会以一个角度斜抛n个炸弹,然后问你最多有多少个炸弹能够炸到敌人,却炸不到自己人,敌人在(l1,0)和(r1,0)之间,自己人在(l2,0),(0,r2)之间

题解
枚举角度,然后biubiu的模拟一下,算算物理题~

代码

 

    double g=9.8;
    double sp[maxn];
    int main()
    {
        int n;
        while(RD(n)!=-1&&n)
        {
            double h,l1,r1,l2,r2;
            RDD(h),RDD(l1),RDD(r1),RDD(l2),RDD(r2);
            REP(i,n)
            {
                RDD(sp[i]);
            }
            int ans=0;
            int sum=0;
            for(double i=-pi/2;i<=pi;i+=pi/1000)//枚举角度
            {
                sum=0;//统计有多少个落入第二个区间
                for(int ii=0;ii<n;ii++)//枚举炮弹
                {
                    double vy=sp[ii]*sin(i);//计算vy方向初速度
                    double vx=sp[ii]*cos(i);//计算vx方向初速度
                    double t0=sqrt(2*g*h+vy*vy)-vy;//计算时间
                    t0/=g;
                    double d=vx*t0;//计算x轴位移
                    if(d>=l2&&d<=r2)//统计
                    {
                        sum=0;
                        break;
                    }
                    if(d>=l1&&d<=r1)
                        sum++;
                }
                ans=max(sum,ans);
            }
            cout<<ans<<endl;
        }
    }

 

    原文作者:qscqesze
    原文地址: https://www.cnblogs.com/qscqesze/p/4331493.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞