6TH HUNAN COLIGIANTE PROGRAMING CONTEST -- PROBLEM D

Since I'm on the road to IELTS,all my articals in this period will be english!

Here's simple problem in the hunan provincial.(uva 11880 Ball in a Rectangle)

Well,the meaning for short , is to calculate the position of a ball in the table after moving a distance,given the original coordinate , the speed and direction it moves.

The solution is to expand the table, knows the total distance and divides it into x-coordinate and  y-coordinate,calculate the position respectively.

Here is the accepted code:

 

#include<iostream>

#include<cmath>

using namespace std;

int main()

{

int L,W,x,y,R,a,v,s,k;

double lx,ry,fx,fy;

double pp=3.141592653589793;

long long dis,t;

while(scanf("%d%d%d%d%d%d%d%d",&L,&W,&x,&y,&R,&a,&v,&s) && (L||W))

{

L-=2*R;W-=2*R;

x-=R,y-=R;

dis=(long long)v*s;

ry=dis*sin((double)a/360*2*pp)+y;

lx=dis*cos((double)a/360*2*pp)+x;

 

t=(long long)lx/L;

if(t%2)

{

if(lx<0)

fx=L+(lx-t*L)+R;

else

fx=L-(lx-t*L)+R;

}

else

{

if(lx<0)

fx=-lx+t*L+R;

else

fx=lx-t*L+R;

}

 

t=(long long)ry/W;

if(t%2)

{

if(ry<0)

fy=W+(ry-t*W)+R;

else

fy=W-(ry-t*W)+R;

}

else

{

if(ry<0)

fy=-ry+t*W+R;

else

fy=ry-t*W+R;

}

 

printf("%.2lf %.2lf/n",fx,fy);

}

return 0;

}

 

I didn't AC this problem due to the unaccurate PI-value during the contest,which remained a pity!But as a beginner,I was happy to receive the second prize of Hunan Provincial Collegiate Programming Contest! I would like to give my thanks to my team mates.

2010-11-09/2011-04-10

你可能感兴趣的:(table,360,2010,distance)