首页 > ACM题库 > HDU-杭电 > HDU 3940-The Angry Birds[解题报告]HOJ
2015
04-14

HDU 3940-The Angry Birds[解题报告]HOJ

The Angry Birds

问题描述 :

“Lemme tell ya, these ain’t no ordinary finches we’re talkin’ about. These here are the Angry Birds, the ones that’s gonna kick you in the ‘nads. And they’re the ones on your side. They must be from Galapadapados, or sumptin’.” �C Col. Angus, Bird Expert.
The survival of the Angry Birds is at stake. Dish out revenge on the green pigs who stole the Birds’ eggs. Use the unique destructive powers of the Angry Birds to lay waste to the pigs’ fortified castles.
There are 3 kinds of bird in Angry Birds Army — the Red bird, the Yellow bird and the Blue bird. To destroy the pigs’ fortified castles, birds will be shot by a sling. Different kind of birds has different flying routes after they are shot.
In this world, the acceleration of gravity is 9.8 m/(s^2);
1.The Red Bird:
The Red Bird’s route is a normal parabola (抛物线) .
Sticks and Right Triangle

2.The Yellow Bird:
The Yellow Bird can accelerate. The Yellow Bird’s flying route is the same as The Red Bird before it accelerate. After The Yellow Bird accelerate, both its horizontal velocity and its vertical velocity will be doubled at once(the bird is still affected by gravity after accelerating).
Sticks and Right Triangle

3.The Blue Bird:
The Blue Bird can split itself to 3 birds. The Blue Bird’s flying route is the same as The Red Bird before it splits itself. After it splitting, The Blue Bird split itself to 3 birds with different horizontal velocities (but they have same vertical velocities).
Sticks and Right Triangle

As the Angry Bird Army’s general, you must know the horizontal distance between the point(s) where the bird(s) touch the land and the sling.

输入:

The input consists of multiple test cases.
Each test case has only one line which has 3 types according to different kind of birds.

H Red Vx Vy
H Yellow Vx Vy t
H Blue Vx Vy t V1 V2 V3

H the height of the sling.
Vx and Vy are the horizontal and vertical velocities when they are shot.
t is the time when the Yellow Bird accelerate or the Blue Bird splits after they are shot.
V1,V2,V3 are the horizontal velocities of the 3 birds split by the Blue Bird.

Notice: If the bird accelerate or split after the bird reach the land,nothing will happen;

0<=H,Vx,Vy,t,V1,V2,V3<=1000

输出:

The input consists of multiple test cases.
Each test case has only one line which has 3 types according to different kind of birds.

H Red Vx Vy
H Yellow Vx Vy t
H Blue Vx Vy t V1 V2 V3

H the height of the sling.
Vx and Vy are the horizontal and vertical velocities when they are shot.
t is the time when the Yellow Bird accelerate or the Blue Bird splits after they are shot.
V1,V2,V3 are the horizontal velocities of the 3 birds split by the Blue Bird.

Notice: If the bird accelerate or split after the bird reach the land,nothing will happen;

0<=H,Vx,Vy,t,V1,V2,V3<=1000

样例输入:

1 Red 1 2
2 Blue 3 4 1 1 2 3
2 Blue 3 4 10 1 2 3
5 Yellow 3 4 1

样例输出:

0.700
3.166 3.333 3.499
3.499
4.874

/*
分析:
    物理题,注意别漏掉步骤就行了。

                               2012-10-15
*/

#include"stdio.h"
#include"string.h"
#include"math.h"
#define g 9.8
int main()
{
	double h,v_x,v_y,t,v1,v2,v3;
	double t1,t2;
	double ans,ans1,ans2,ans3;
	double temp;
	char str[11];
	while(scanf("%lf",&h)!=-1)
	{
		scanf("%s%lf%lf",&str,&v_x,&v_y);
		t1=v_y/g;
		t2=sqrt(2*h/g+v_y*v_y/g/g);
		if(strcmp(str,"Red")==0)
		{
			printf("%.3lf\n",(t1+t2)*v_x);
			continue;
		}
		else if(strcmp(str,"Yellow")==0)
		{
			scanf("%lf",&t);
			if(t>=t1+t2)	{printf("%.3lf\n",(t1+t2)*v_x);continue;}
			else if(t<=t1)
			{
				temp=(v_y+v_y-t*g)*t/2;
				h+=temp;
				ans=v_x*t;
				v_y-=t*g;
				v_y*=2;
				v_x*=2;
				t1=v_y/g;
				t2=sqrt(2*h/g+v_y*v_y/g/g);
				ans+=v_x*(t1+t2);
				printf("%.3lf\n",ans);
			}
			else
			{
				ans=v_x*t;
				h+=0.5*v_y*v_y/g;
				h-=0.5*g*(t-t1)*(t-t1);
				v_y=2*g*fabs(t-t1);
				v_x*=2;
				t2=(-v_y+sqrt(v_y*v_y+2*g*h))/g;
				ans+=v_x*t2;
				printf("%.3lf\n",ans);
			}
		}
		else if(strcmp(str,"Blue")==0)
		{
			scanf("%lf%lf%lf%lf",&t,&v1,&v2,&v3);
			if(t>=t1+t2)	{printf("%.3lf\n",(t1+t2)*v_x);continue;}
			if(t<=t1)
			{
				temp=(v_y+v_y-t*g)*t/2;
				h+=temp;
				ans=v_x*t;
				v_y-=t*g;
				t2=sqrt(2*h/g+v_y*v_y/g/g);
				ans1=ans+v1*(t2+t1-t);
				ans2=ans+v2*(t2+t1-t);
				ans3=ans+v3*(t2+t1-t);
				printf("%.3lf %.3lf %.3lf\n",ans1,ans2,ans3);
			}
			else
			{
				ans=v_x*t;
				h+=0.5*v_y*v_y/g;
				h-=0.5*g*(t-t1)*(t-t1);
				v_y=g*fabs(t-t1);
				t2=(-v_y+sqrt(v_y*v_y+2*g*h))/g;
				ans1=ans+v1*t2;
				ans2=ans+v2*t2;
				ans3=ans+v3*t2;
				printf("%.3lf %.3lf %.3lf\n",ans1,ans2,ans3);
			}
		}
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

参考:http://blog.csdn.net/ice_crazy/article/details/8073095


  1. #include <cstdio>
    #include <algorithm>

    struct LWPair{
    int l,w;
    };

    int main() {
    //freopen("input.txt","r",stdin);
    const int MAXSIZE=5000, MAXVAL=10000;
    LWPair sticks[MAXSIZE];
    int store[MAXSIZE];
    int ncase, nstick, length,width, tmp, time, i,j;
    if(scanf("%d",&ncase)!=1) return -1;
    while(ncase– && scanf("%d",&nstick)==1) {
    for(i=0;i<nstick;++i) scanf("%d%d",&sticks .l,&sticks .w);
    std::sort(sticks,sticks+nstick,[](const LWPair &lhs, const LWPair &rhs) { return lhs.l>rhs.l || lhs.l==rhs.l && lhs.w>rhs.w; });
    for(time=-1,i=0;i<nstick;++i) {
    tmp=sticks .w;
    for(j=time;j>=0 && store >=tmp;–j) ; // search from right to left
    if(j==time) { store[++time]=tmp; }
    else { store[j+1]=tmp; }
    }
    printf("%dn",time+1);
    }
    return 0;
    }

  2. 嗯 分析得很到位,确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样:push时,比较要push的elem和辅助栈的栈顶,elem<=min.top(),则min.push(elem).否则只要push(elem)就好。在pop的时候,比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();},否则{stack.pop();}.

  3. Hello Web Admin, I noticed that your On-Page SEO is is missing a few factors, for one you do not use all three H tags in your post, also I notice that you are not using bold or italics properly in your SEO optimization. On-Page SEO means more now than ever since the new Google update: Panda. No longer are backlinks and simply pinging or sending out a RSS feed the key to getting Google PageRank or Alexa Rankings, You now NEED On-Page SEO. So what is good On-Page SEO?First your keyword must appear in the title.Then it must appear in the URL.You have to optimize your keyword and make sure that it has a nice keyword density of 3-5% in your article with relevant LSI (Latent Semantic Indexing). Then you should spread all H1,H2,H3 tags in your article.Your Keyword should appear in your first paragraph and in the last sentence of the page. You should have relevant usage of Bold and italics of your keyword.There should be one internal link to a page on your blog and you should have one image with an alt tag that has your keyword….wait there's even more Now what if i told you there was a simple WordPress plugin that does all the On-Page SEO, and automatically for you? That's right AUTOMATICALLY, just watch this 4minute video for more information at.