zoukankan      html  css  js  c++  java
  • HDU 4445 Crazy Tank (枚举)

    D - Crazy Tank
    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

    解题思路:直接枚举角度即可,公式 [v*sin(#)/g + sqrt((2 * (H + pow(v*sin(#), 2)/2*g ))/g)]*v*cos(#)  其中#为角度

    解题代码:

     1 #include <stdio.h>
     2 #include <math.h>
     3 const double PI = 3.1415926;
     4 int main()
     5 {
     6     int n;
     7     double h,x,y,x1,y1;
     8     double f[210];
     9     while (~scanf("%d",&n)&&n)
    10     {
    11         int max=0;
    12         scanf("%lf%lf%lf%lf%lf",&h,&x,&y,&x1,&y1);
    13         for (int i=1;i<=n;i++)
    14         scanf("%lf",&f[i]);
    15         double add = PI/1000;
    16         for (double i = -PI/2;i <= PI/2 ;i += add)
    17         {
    18             int t = 0;
    19             for (int j = 1; j <= n; j ++)
    20             {
    21                 double s;
    22                 s=(sqrt(((f[j]*sin(i))*(f[j]*sin(i))/(2*9.8)+h)*2/9.8) + (f[j]*sin(i)/9.8))*f[j]*cos(i);
    23                 if ((s>=x) && (s<=y) )
    24                 {    
    25                     t++;
    26                 }
    27                 if (s>=x1 && s<=y1) 
    28                 {
    29                     t = 0;
    30                     break;
    31                 }
    32             }
    33             if (max < t) max = t;
    34         }
    35         printf("%d\n",max);
    36     }
    37     return 0;
    38 }
    View Code G++
     
  • 相关阅读:
    Android手势锁实现
    网页模板pug基本语法
    React入门看这篇就够了
    我曾站在离你最近的天涯
    一文看懂浏览器事件循环
    Vi编辑网卡
    2019.6.11_MySQL进阶二:主键与外键
    2019.6.13_笔试题目及答案
    2019.6.13_MySQL简单命令的使用
    2019.6.13_SQL语句中----删除表数据drop、truncate和delete的用法
  • 原文地址:https://www.cnblogs.com/shengshouzhaixing/p/3097591.html
Copyright © 2011-2022 走看看