HDU 4445(计算几何+暴力)

来源:互联网 发布:奥林巴斯25mm1.8知乎 编辑:程序博客网 时间:2024/05/17 17:46

问题描述:

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

210 10 15 30 3510.020.0210 35 40 2 3010.020.00
Sample Output

10

题目题意:题目给我们一个炮台高度H,N枚炮弹,让我们设计一个角度使得更多的炮弹落在[L1,R1],不允许落到[L2,R2]区间内。

题目分析:我们枚举在y轴正方向到y轴负方向内的角度(每一次加上一个小角度)。算出每个角度时,符合要求的炮弹量。

代码如下:

#include<iostream>#include<cstdio>#include<cstring>#include<cmath>using namespace std;const double g=9.80;const double PI=acos(-1.0);const double epx=PI/1000;const int maxn=205;double v[maxn],x[maxn];double H,L1,R1,L2,R2;int n,ans;void solve(double angle){    int cur=0;    for (int i=0;i<n;i++) {        double res=sqrt(v[i]*v[i]*cos(angle)*cos(angle)+2*g*H);        double t=(v[i]*cos(angle)+res)/g;        x[i]=v[i]*sin(angle)*t;    }    for (int i=0;i<n;i++) {        if (x[i]>=L1&&x[i]<=R1)            cur++;        if (x[i]>=L2&&x[i]<=R2) {//只要有炮弹落在这里,就不符合要求            cur=0;            break;        }    }    ans=max(ans,cur);}int main(){    while (scanf("%d",&n)!=EOF) {        if(n==0) break;        scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2);        for (int i=0;i<n;i++)            scanf("%lf",&v[i]);        ans=0;        for (double i=0;i<=PI;i+=epx) {            solve (i);        }        printf("%d\n",ans);    }    return 0;}









原创粉丝点击