HDU 4445 数学-抛物运动

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

题解:角度可以向下,向上,其实都一样的计算.................将pi分块枚举,维护最大答案就好了

///1085422276
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<bitset>
#include<set>
#include<vector>
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&&xx<R2+eps)
                {
                    sum=0;
                    break;
                }
                if(xx>L1-eps&&xx<R1+eps)
                    sum++;
            }
            ans=max(sum,ans);
            /// if(flag==1)break;
        }
        printf("%d\n",ans);
    }
    return 0;
}

代码

时间: 2024-12-20 01:05:36

HDU 4445 数学-抛物运动的相关文章

hdu 4961 数学杂题

http://acm.hdu.edu.cn/showproblem.php?pid=4961 先贴个O(nsqrtn)求1-n所有数的所有约数的代码: vector<int>divs[MAXN]; void caldivs() { for(int i=1;i<MAXN;i++) for(int j=i;j<MAXN;j+=i) divs[j].push_back(i); } 有了这个当时理下思路就可写了,但是重复数处理注意: 1.用一个数组vis[]  vis[i]=1表示i存在

hdu 4445 Crazy Tank(枚举)

http://acm.hdu.edu.cn/showproblem.php?pid=4445 要求发射的炮弹在都不落在friendly tank区域的条件下落在enemy tank区域的最多数目. 直接暴力枚举角度.. #include <stdio.h> #include <iostream> #include <map> #include <set> #include <bitset> #include <list> #inclu

HDU 5976 数学,逆元

1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更大(当然不能拆1).所以容易想到是拆成2+3+...+n+s=x,先求出n即2+3+...+n<x<2+3+...+n+(n+1),然后将某个数向右平移s个单位变为n+1即可.注意:(1)预处理出前缀和,前缀积.(2)将某个数移到n+1,要除这个数再乘n+1,这里要用逆元,也要预处理出来. #in

*HDU 2451 数学

Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1723    Accepted Submission(s): 675 Problem Description A luxury yacht with 100 passengers on board is sailing on the s

【HDU 4445】Crazy Tank(暴力)

高中物理斜抛运动,简单分析一下角度固定下来则可以计算每个cannonball的降落坐标lnd. 因此暴力计算不同角度下的结果. #include <cstdio> #include "cmath" #include "algorithm" #define ll long long #define dd double #define N 205 #define g 9.8 #define eps 1e-6 const dd pi=acos(-1.0); l

hdu 4811 数学 不难

http://acm.hdu.edu.cn/showproblem.php?pid=4811 因为看到ball[0]>=2 && ball[1]>=2 && ball[2]>=2  ans=(sum-6)*6+15    sum是三种颜色的球个数的和,然后就想到分类讨论,因为情况是可枚举的, 发现整数如果不加LL直接用%I64d打印会出问题 //#pragma comment(linker, "/STACK:102400000,102400000

[ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂

从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了一发没过 上网看了一下才知道是快速幂 而且特征方程的推导简直精妙 尤其是共轭相抵消的构造 真的是太看能力了 (下图转自某大神博客) 特征方程是C^2=-2*a*C+(a*a-b) 然后用快速幂求解 临时学了下矩阵快速幂 从这道题能看出来 弄ACM真的要数学好 这不是学校认知的高数 线代 概率分数 而

hdu 4506(数学,循环节+快速幂)

小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 5427    Accepted Submission(s): 1461 Problem Description 小明自从告别了ACM/ICPC之后,就开始潜心研究数学问题了,一则可以为接下来的考研做准备,再者可以借此机会帮助一些同学,尤其是漂亮的师妹.这 不,班

hdu 5399(数学推理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5399: 题意: 给你m个函数f1,f2,?,fm:{1,2,?,n}→{1,2,?,n}(即所有的x∈{1,2,?,n},对应的f(x)∈{1,2,?,n}),已知其中一部分函数的函数值,问你有多少种不同的组合使得所有的i(1≤i≤n),满足f1(f2(?fm(i)))=i 对于函数集f1,f2,?,fm and g1,g2,?,gm,当且仅当存在一个i(1≤i≤m),j(1≤j≤n),fi(j)≠