zoukankan      html  css  js  c++  java
  • hdu 4445 Crazy Tank (暴力枚举)

    Crazy Tank

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 4562    Accepted Submission(s): 902


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


    这题也是醉了,居然暴力枚举,一直推公式了。

    对于[-PI/2,PI/2]区间,每次累加一个较小值。遍历N个区间。求得满足条件最多的那个就是答案。

    #include<stdio.h>
    #include<string.h>
    #include<math.h>
    #include<algorithm>
    using namespace std;
    #define N 205
    #define LL __int64
    const double eps=1e-9;
    const double PI=acos(-1.0);
    double h,l1,l2,r1,r2;
    double v[N],g=9.8;
    int n;
    int fun(double anl)
    {
        int i,tmp=0;
        double vx,vy1,vy2,t,x;
        for(i=0;i<n;i++)
        {
            vx=v[i]*cos(anl);
            vy1=v[i]*sin(anl);
            vy2=sqrt(vy1*vy1+2*g*h);
            t=(vy1+vy2)/g;
            x=vx*t;
            if(x>=l2 &&x<=r2 )
                return 0;
            if(x>=l1 &&x<=r1 )
                tmp++;
        }
        return tmp;
    }
    int main()
    {
        int i;
        while(scanf("%d",&n),n)
        {
            scanf("%lf%lf%lf%lf%lf",&h,&l1,&r1,&l2,&r2);
            for(i=0;i<n;i++)
            {
                scanf("%lf",&v[i]);
            }
            double a,add=PI/1000;
            int ans=0;
            for(a=-PI/2;a<=PI/2 ;a+=add)
            {
                int tmp=fun(a);
                ans=max(ans,tmp);
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
    


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    后台管理系统文件三部曲之——第三部曲实现文件的查看预览
    后台管理系统文件三部曲之——第二部曲实现文件的下载
    后台管理系统文件三部曲之——第一部曲实现文件的上传
    数组includes的使用之在字典里获取数据
    在Swift3里面实现点击不同按钮播放不同声音的一种实现方法
    如何在Swift3中获取Json包的内容(unwrap Json package)
    点击TableView任一行跳转详情页面会跳转两次的解决办法
    UITableView数据不显示(在console中已显示相应数据)
    关于“代理”(delegate)我的一点浅见
    出现 warning "Unknown class _??????????View in Interface Builder file."的原因
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/4727676.html
Copyright © 2011-2022 走看看