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\n",ans);
}
return 0;
}

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

hdu 4445 Crazy Tank (暴力枚举)的更多相关文章

  1. hdu 4445 Crazy Tank(物理过程枚举)

    遇到物理题,千万不要一味的当成物理题去想着推出一个最终结果来,这样ACM竞赛成了物理比赛,出题人就没水平了...往往只需要基础的物理分析,然后还是用算法去解决问题.这题n小于等于200,一看就估计是暴 ...

  2. [物理题+枚举] hdu 4445 Crazy Tank

    题意: 给你N个炮弹的发射速度,以及炮台高度H和L1,R1,L2,R2. 问任选发射角度.最多能有几个炮弹在不打入L2~R2的情况下打入L1~R1 注意:区间有可能重叠. 思路: 物理题,发现单纯的依 ...

  3. HDU 4445 Crazy Tank --枚举

    题意: n个物体从高H处以相同角度抛下,有各自的初速度,下面[L1,R1]是敌方坦克的范围,[L2,R2]是友方坦克,问从某个角度抛出,在没有一个炮弹碰到友方坦克的情况下,最多的碰到敌方坦克的炮弹数. ...

  4. hdu 4445 Crazy Tank

    #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...

  5. HDU 4445 Crazy Tank 高中物理知识忘得差不多了

    题意不难理解,仔细看题吧,就不说题意了 #include <iostream> #include <cstdio> #include <cstring> #incl ...

  6. hdoj 4445 Crazy Tank 物理题/枚举角度1

    Crazy TankTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  7. HDU 5778 abs (暴力枚举)

    abs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Problem De ...

  8. HDU 1015.Safecracker【暴力枚举】【8月17】

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is lo ...

  9. HDU - 5128The E-pang Palace+暴力枚举,计算几何

    第一次写计算几何,ac,感动. 不过感觉自己的代码还可以美化一下. 传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5128 题意: 在一个坐标系中,有n个 ...

随机推荐

  1. svn 使用(一个)

    一个. 安装svn  server(操作系统centos) yum install subversion 通过 subversion -v 如果成功安装命令来查看 温馨提示不承担任何subversio ...

  2. delegate实现Javascript的each方法

    C#如何用delegate实现Javascript的each方法   C#中有很多易混淆的关键词,例如delegate,Func, Action和 Predicate.Func, Action和 Pr ...

  3. CentOS7卸载KDE桌面(转)

    最初安装centos时选择了安装KDE桌面,打开很卡,没有用到,想卸载,可是试了网上的方法什么yum groupremove kde-desktop 都不奏效,于是只能自己找出KDE的包,然后yum卸 ...

  4. 关于程序猿怎样降低程序Bug的若干建议

    毫无疑问,程序猿是善于思考问题的一族. 一个程序的编写都是通过:思考.设计.编写.调试.測试以及执行这些主要的阶段. 但大部分程序猿都有一个问题就是不太愿意測试自己的代码. 他们草草的调式完毕以后就觉 ...

  5. MySQL各种日期类型与整型(转)

    日期类型 存储空间 日期格式 日期范围 datetime 8 bytes YYYY-MM-DD HH:MM:SS 1000-01-01 00:00:00 ~ 9999-12-31 23:59:59 t ...

  6. Android-Service组件

    转载请标明出处:http://blog.csdn.net/goldenfish1919/article/details/40381109 原文:http://developer.android.com ...

  7. MVC 5 Ajax + bootstrap+ handle bar 例: 实现service 状态

    Js Script <script src="../../Scripts/handlebars-v1.3.0.js"></script> <scrip ...

  8. Chrome 扩展 最近的历史 HistoryBar v1.1

    说明 以前用过一段时间傲游浏览器,渐渐的习惯了它的鼠标手势和一些细微的人性化的功能.比方地址栏左边的"近期訪问的页面"button.能够方便的找到近期 20 条历史记录. wate ...

  9. Iterator、Iterable接口的使用及详解

    Java集合类库将集合的接口与实现分离.同样的接口,可以有不同的实现. Java集合类的基本接口是Collection接口.而Collection接口必须实现Iterator接口. 以下图表示集合框架 ...

  10. Design Pattern Command 命令设计模式

    这种设计模式是使用不同类的包裹不同的命令,达到什么样的命令执行什么操作. 有可能进一步利用map您最喜欢的对接命令字. 正在运行的类实际上已经包含了操作的所有需求,例如: class SuperMak ...