编程介的小学生 2017-11-18 02:13 采纳率: 20.5%
浏览 612
已结题

Crazy Tank

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

  • 写回答

1条回答 默认 最新

  • zhaihuadefennu 2018-08-02 07:25
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型