hdu-4445 暴力枚举

来源:互联网 发布:好用的网络云盘 编辑:程序博客网 时间:2024/05/21 11:23

这个题,昨天在做训练赛的时候,和队友商量出来是暴力枚举角度,但是暴力枚举角度,自己不会枚举

比赛结束后,问了一个学长,double x1 = atan(1)*4; 这个是用来表示180度是最好的方法,还有这个题的精度也需要控制,一开始是除以10000超时,后来改为

 for(x = 0; x <= x1; x += (x1 / 1000));÷1000就可以过

高中物理抛物线公式     double t = (sqrt(2*9.8*h + vy * vy) + vy) / 9.8; 记得有一个位置,往上抛cos(p) < 0 所以那个速度的函数为 -vy + gt;

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <vector>#include <string>#include <map>#include <math.h>#include <stack>#define LL long longusing namespace std;const int INF = 0x3f3f3f3f;int main(){    double h,l1,r1,l2,r2,x;    double vx,vy;    int num;    int sum ;    double v[210];    while(scanf("%d",&num)&&num)    {        scanf("%lf%lf%lf%lf%lf",&h,&l1,&r1,&l2,&r2);        for(int i = 0; i < num; i++)        {            scanf("%lf",&v[i]);        }        int ans = 0;        double x1 = atan(1)*4;        for(x = 0; x <= x1; x += (x1 / 1000))        {            sum = 0;            for(int i = 0; i < num; i++)            {                vy = v[i]*cos(x);                vx = v[i]*sin(x);                double t = (sqrt(2*9.8*h + vy * vy) + vy) / 9.8;                double s = vx * t;                //cout<<s<<endl;                if(s >= l2 && s <= r2)                {                    sum = 0;                    break;                }                else if(s >= l1 && s <= r1)                {                    sum++;                    // cout<<"*"<<endl;                }            }            if(sum > ans)                ans = sum;        }        printf("%d\n",ans);    }    return 0;}

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,R1L1,R1 (two ends are included). As the same reason, it will be considered hitting friendly tank if it lands between L2,R2L2,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


原创粉丝点击