HDU 4445 Crazy Tank (Violent enumeration)

Source: Internet
Author: User
Tags float number

Crazy TankTime limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4562 Accepted Submission (s): 902


Problem Descriptioncrazy Tank was a famous game about ten years ago. Every child liked it. Time flies, children grow up, but the memory of happy childhood would never go.

Now your ' re controlling the tank Laotu on a platform which is H meters above the ground. Laotu is, so, can only choose a shoot angle (all the angle are available) before game start and then any Adjustin G 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 are an enemy tank in the ground with coordination (L1, R1) and a friendly tank with Coordin ation (L2, R2). A Cannonball is considered hitting enemy tank if it lands on the ground between [L1,R1] (both ends are included). As the same reason, it'll 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 hits the enemy tank under the condition that no cannonb All hits friendly tank.
The g equals to 9.8.
Inputthere is multiple test case.
Each test case contains 3 lines.
The first line contains a 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. 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.
Outputfor Each test case, you should output an integer in a single line which indicates the max number of cannonballs hits 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
TenHintin the first case one of the best choices are that shoot the cannonballs parallelly to the horizontal line, Then the first cannonball lands in 14.3 and the second lands on 28.6.In the second there are no shoot angle to do any can Nonball land between [35,40] on the condition that no cannonball lands between [2,30].


This problem is also drunk, incredibly violent enumeration, has been pushing the formula.

For the [-PI/2,PI/2] interval, a smaller value is added each time. Traverse n intervals. The answer is the one that satisfies most of the conditions.

#include <stdio.h> #include <string.h> #include <math.h> #include <algorithm>using namespace STD; #define N 205#define LL __int64const double eps=1e-9;const double Pi=acos ( -1.0);d ouble 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<n;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", &AMP;H,&AMP;L1,&AMP;R1,&AMP;L2,&AMP;R2);        for (i=0;i<n;i++) {scanf ("%lf", &v[i]);        } double a,add=pi/1000;        int ans=0;            for (A=-PI/2;A&LT;=PI/2; a+=add) {int tmp=fun (a);        Ans=max (ANS,TMP);    } printf ("%d\n", ans); } return 0;} 


Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

HDU 4445 Crazy Tank (Violent enumeration)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.