向下发展发射的角度也正是180°,问从有些角度抛出澳门皇冠官网app

 

Crazy Tank

Time
Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K
(Java/Others)
Total
Submission(s): 6047    Accepted Submission(s): 1318

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.

澳门皇冠官网app 1

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

 

Source

2012 Asia JinHua Regional
Contest

题意:1个火炮在高度为H的地点接二连三发出炮弹,须求炮弹落在敌方坦克上,不可能落在友方上,先固定发射的角度,然后角度不能够变了,打出装有的炮弹。

思路:纯物理题啊,当时怀想到发展发射和向下发出二种境况,把标题的量化了,结果求向下发出的小时还要用求根公式,那样就劳动了。其实想想记忆在此以前高级中学所学,我们得以把那些难点矢量化,取向下为正方向,速度用位移(位移的变更也正是H,省去中间路程的怀念),时间用竖直分量下的进程矢量变化来求得,那样就简化了求水平位移的求解。
角度转弧度,相当于 度数*π/180,1个π也正是180°,我们一般用sin1陆.67%π =
八分之四。向下发展发射的角度也正是180°,一个π的界定,能够分为一千份,每回枚举扩大π/一千大笑,知足则++。

第叁正是Vy*Vy-Vy0*Vy0=2gH,那个公式的接头,终归高级中学过去那么久了,对矢量位移的变化公式通晓少了一些就忘了。

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
const int MAXN=200+5;
const double PI=acos(-1.0);//定义π大小
const double g=9.8;
double v[MAXN],L1,R1,L2,R2,H;
int n;

int meiju(double x)//角度为x;
{
    int ans=0;
    for(int i=0;i<n;i++)
    {
        double Vy0=v[i]*sin(x); //竖直分量的初速度,当向上发射时,为-PI,初速度的竖直分量为负
        double Vx0=v[i]*cos(x); //水平分量的速度不变
        double Vy=sqrt(2*g*H+Vy0*Vy0); //矢量位移公式Vy*Vy-Vy0*Vy0=2gH,H为竖直分量上的位移大小。注意规定向下为正方向后,Vy肯定为正数,绝对值直接去掉
        double t=(Vy-Vy0)/g; //如果Vy0是向上打的,则为负,速度变化量相当于两个速度的相加,除以加速度,得出时间
        double d=Vx0*t;

        if(d>=L2&&d<=R2)
            return 0;
        if(d>=L1&&d<=R1)
            ans++;
    }
    return ans;
}
int main()
{
    while(scanf("%d",&n)!=EOF && n)
    {
        scanf("%lf%lf%lf%lf%lf",&H,&L1,&R1,&L2,&R2);
        for(int i=0;i<n;i++)
          scanf("%lf",&v[i]);

        double add=PI/1000;//最好分细一点

        int ans=0;

        for(double x=-PI/2;x<=PI/2;x+=add) //角度从竖直向上开始打到竖直向下,一个π的范围
          ans=max(ans,meiju(x));
        printf("%d\n",ans);
    }
    return 0;
}

 
 

澳门皇冠官网app 2澳门皇冠官网app 3

题意:
n个物体从高H处以相同角度抛下,有各自的初速度,上边[L1,R1]是敌手坦克的界定,[L2,R2]是友方坦克,问从某些角度抛出,在并未有多个炮弹际遇友方坦克的景况下,最多的相遇敌方坦克的炮弹数。

#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;
}

View Code

代码:

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

相关文章