HDU 4445 Crazy Tank --枚举

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

解法: 枚举角度,将pi/2分成1000份,然后枚举,通过方程 v*sin(theta)*t - 1/2*g*t^2 = -H 解出t,然后 x = v*cos(theta)*t算出水平距离,直接统计即可。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#define pi acos(-1.0)
#define eps 1e-8
using namespace std;
#define N 207
#define g 9.8

double V[N];
double H;

int sgn(double x)
{
    if(x > eps) return 1;
    if(x < -eps) return -1;
    return 0;
}

double calc(double theta,double v)
{
    double up = v*sin(theta) + sqrt(v*v*sin(theta)*sin(theta)+2.0*g*H);
    double down = g;
    return v*cos(theta)*up/down;
}

int main()
{
    double L1,R1,L2,R2;
    int n,i,j;
    while(scanf("%d",&n)!=EOF && n)
    {
        scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2);
        if(sgn(L1-L2) == 0 && sgn(R1-R2) == 0) { puts("0"); continue; }
        for(i=1;i<=n;i++) scanf("%lf",&V[i]);
        double delta = pi*0.001;
        int Maxi = 0;
        for(i=0;i<=1000;i++)
        {
            double theta = delta*i - pi/2.0;
            int cnt = 0;
            for(j=1;j<=n;j++)
            {
                double x = calc(theta,V[j]);
                if(sgn(x-L2) >= 0 && sgn(x-R2) <= 0)
                {
                    cnt = 0;
                    break;
                }
                if(sgn(x-L1) >= 0 && sgn(R1-x) >= 0)
                    cnt++;
            }
            Maxi = max(Maxi,cnt);
        }
        cout<<Maxi<<endl;
    }
    return 0;
}

时间: 2024-10-15 00:53:26

HDU 4445 Crazy Tank --枚举的相关文章

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 f

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 4445 Crazy Tank(物理过程枚举)

遇到物理题,千万不要一味的当成物理题去想着推出一个最终结果来,这样ACM竞赛成了物理比赛,出题人就没水平了...往往只需要基础的物理分析,然后还是用算法去解决问题.这题n小于等于200,一看就估计是暴力枚举能过.就枚举角度就行了. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<string> 6 #include

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

题意: 给你N个炮弹的发射速度,以及炮台高度H和L1,R1,L2,R2. 问任选发射角度.最多能有几个炮弹在不打入L2~R2的情况下打入L1~R1 注意:区间有可能重叠. 思路: 物理题,发现单纯的依据V去求X很困难. 这个时候想到暴力枚举角度.for(double i=0; i<=pi; i+=0.0007) 算出能到达的x.然后推断x,统计sum 发现以增长级0.0007弧度 刚刚好能过这道题 反正也是醉了~ 代码: #include"cstdlib" #include&qu

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

Crazy TankTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5033    Accepted Submission(s): 1017 Problem DescriptionCrazy Tank was a famous game about ten years ago. Every child liked it. Time fli

HDOJ 4445 Crazy Tank

枚举角度 Crazy Tank Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4305    Accepted Submission(s): 833 Problem Description Crazy Tank was a famous game about ten years ago. Every child liked it. T

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

HDU 3157 Crazy Circuits(有源汇上下界最小流)

HDU 3157 Crazy Circuits 题目链接 题意:一个电路板,上面有N个接线柱(标号1~N),还有两个电源接线柱 + -,给出一些线路,每个线路有一个下限值求一个可以让所有部件正常工作的总电流 没有则输出impossible 思路: 有源汇有上下界求最小流,建模方法为: 按无源汇先建图,跑超级源汇ss->tt一次,然后加入t->s,容量INF的边,在跑一次ss->tt,如果是满流,就有解,解为t->s边的当前流量 顺带写个最大流的,最大流就先把t->s加入直接跑

HDU 3709 Balanced Number 枚举+数位DP

枚举支点之后数位DP,注意姿势 #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <climits> #include <string> #include <iostream> #include <map> #include <cstdlib> #include <list&g