HDU-4445 Crazy Tank

HDU-4445 Crazy Tank

            Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

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.

HDU-4445 Crazy Tank_第1张图片
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

#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
using namespace std;
double v[300];
#define PI acos(-1.0)
#define add PI/1000
int n;
double h,l1,r1,l2,r2;
int solve(double i)
{
    int cnt = 0;
    int flag = 1;
    for (int j = 0; j < n; j++)
    {
        double vy = v[j] * cos(i);
        double vx = v[j] * sin(i);
        double t = ((sqrt(vy *  vy + 2 * 9.8 * h)) - vy ) / 9.8;
        double x = vx * t;
        if (x >= l2 && x <= r2)
        {
            return 0;
        }
        if (x >= l1 && x <= r1)
        {
            cnt++;
        }
    }
    return cnt;
}
int main() 
{
    while(cin >> n)
    {
        if (n == 0)
            break;
        cin >> h >> l1 >> r1 >> l2 >> r2;
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
        }
        int maxnum = 0;
        double i = 0;
        while(i < PI)
        {
            int ans = solve(i);
            if (ans > maxnum)
                maxnum = ans;
            i += add;
        }
        cout << maxnum << endl;
    }
    return 0;
}

你可能感兴趣的:(HDU-4445)