热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

HDU4445数学-抛物运动

D-CrazyTank
                                                      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(0may 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

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分块枚举,维护最大答案就好了

///1085422276
#include
#include

#include

#include
<string>
#include

#include

#include

#include

#include

#include
<set>
#include

using namespace std ;
typedef
long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a) scanf("%d",&a)
#define mod 365*24*60*60
#define inf 100000
#define maxn 300000
inline ll read()
{
ll x
=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-')f=-1;
ch
=getchar();
}
while(ch>='0'&&ch<='9')
{
x
=x*10+ch-'0';
ch
=getchar();
}
return x*f;
}
//****************************************
#define g 9.8
#define eps 0.0000001
int n;
double s[202],H,L1,L2,R1,R2;
int flag=0;
int suan(int i,double j)
{
double ss=cos(j)*s[i];
double t=sqrt(2*H/g);
double d=t*ss;
if(L1-d<0.0000001)flag=1;
int sum=0;
if(d-L1>=0.0000001&&0.0000001<=R1-d)sum++;
if(d-L2>=0.0000001&&0.0000001<=R2-d) sum--;
if(sum<0)return 0;
return sum;
}
int main()
{

while(READ(n)!=EOF)
{
if(n==0)break;
flag
=0;
scanf(
"%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2);
FOR(i,
1,n)
{
scanf(
"%lf",&s[i]);
}
int ans=0;
double vx,vy,xx,yy;
for(double j=0; j<1000; j+=1)
{
double aphl=j*0.003141593;
int sum=0;
FOR(i,
1,n)
{
vx
=s[i]*sin(aphl);
vy
=s[i]*cos(aphl);
xx
=((sqrt(vy*vy+2.0*g*H)-vy)/g)*vx;
if(xx>L2-eps&&xxeps)
{
sum=0;
break;
}
if(xx>L1-eps&&xxeps)
sum++;
}
ans
=max(sum,ans);
/// if(flag==1)break;
}
printf(
"%d\n",ans);
}
return 0;
}
代码

 


推荐阅读
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • 51nod3221祝寿(反向建图优化)
    题目链接感觉忘记了好多东西。求有向图中其余点到一个点的最短距离可以将该图翻转后rundijkstra#include#include ... [详细]
  • 在Android开发中,使用Picasso库可以实现对网络图片的等比例缩放。本文介绍了使用Picasso库进行图片缩放的方法,并提供了具体的代码实现。通过获取图片的宽高,计算目标宽度和高度,并创建新图实现等比例缩放。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • C++字符字符串处理及字符集编码方案
    本文介绍了C++中字符字符串处理的问题,并详细解释了字符集编码方案,包括UNICODE、Windows apps采用的UTF-16编码、ASCII、SBCS和DBCS编码方案。同时说明了ANSI C标准和Windows中的字符/字符串数据类型实现。文章还提到了在编译时需要定义UNICODE宏以支持unicode编码,否则将使用windows code page编译。最后,给出了相关的头文件和数据类型定义。 ... [详细]
  • 先看官方文档TheJavaTutorialshavebeenwrittenforJDK8.Examplesandpracticesdescribedinthispagedontta ... [详细]
  • 本文由编程笔记#小编整理,主要介绍了关于数论相关的知识,包括数论的算法和百度百科的链接。文章还介绍了欧几里得算法、辗转相除法、gcd、lcm和扩展欧几里得算法的使用方法。此外,文章还提到了数论在求解不定方程、模线性方程和乘法逆元方面的应用。摘要长度:184字。 ... [详细]
  • 本文介绍了在MFC下利用C++和MFC的特性动态创建窗口的方法,包括继承现有的MFC类并加以改造、插入工具栏和状态栏对象的声明等。同时还提到了窗口销毁的处理方法。本文详细介绍了实现方法并给出了相关注意事项。 ... [详细]
  • 本文介绍了在Android开发中使用软引用和弱引用的应用。如果一个对象只具有软引用,那么只有在内存不够的情况下才会被回收,可以用来实现内存敏感的高速缓存;而如果一个对象只具有弱引用,不管内存是否足够,都会被垃圾回收器回收。软引用和弱引用还可以与引用队列联合使用,当被引用的对象被回收时,会将引用加入到关联的引用队列中。软引用和弱引用的根本区别在于生命周期的长短,弱引用的对象可能随时被回收,而软引用的对象只有在内存不够时才会被回收。 ... [详细]
  • 本文介绍了一道经典的状态压缩题目——关灯问题2,并提供了解决该问题的算法思路。通过使用二进制表示灯的状态,并枚举所有可能的状态,可以求解出最少按按钮的次数,从而将所有灯关掉。本文还对状压和位运算进行了解释,并指出了该方法的适用性和局限性。 ... [详细]
  • linux进阶50——无锁CAS
    1.概念比较并交换(compareandswap,CAS),是原⼦操作的⼀种,可⽤于在多线程编程中实现不被打断的数据交换操作࿰ ... [详细]
  • [翻译]PyCairo指南裁剪和masking
    裁剪和masking在PyCairo指南的这个部分,我么将讨论裁剪和masking操作。裁剪裁剪就是将图形的绘制限定在一定的区域内。这样做有一些效率的因素࿰ ... [详细]
  • RingBuffer,或者说CircularBuffer,是一个长度固定的缓冲区,当从一端插入元素超过指定的最大长度时,缓冲区另一端的元素 ... [详细]
  • 2月4日每日安全热点节日期间某企远程办公遭XRed攻击 ... [详细]
  • 本文介绍了如何通过维持两个堆来获取一个数据流中的中位数。通过使用最大堆和最小堆,分别保存数据流中较小的一半和较大的一半数值,可以保证两个堆的大小差距为1或0。如果数据流中的数量为奇数,则中位数为较大堆的最大值;如果数量为偶数,则中位数为较大堆的最大值和较小堆的最小值的平均值。可以使用优先队列来实现堆的功能。本文还提供了相应的Java代码实现。 ... [详细]
author-avatar
瘦瘦的胖菇凉
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有