比赛时想着要模拟过程,没法下手,做后没作出开,原来是把速度v分解到x,y方向上。
在一个周期内求解。
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const double PI=acos(-1); //刚开时自己定义的,有误差,偶然发现这个无错。此值为3.141593
const double eps=1e-6;
double fun1(double x,double vx,double s,double r,double l)
{
double c=2*(l-2*r);
if(vx==0) return x;
double t1=c/vx;
while(s-t1>=0+eps) s-=t1;
double len,tt;
if(s==0+eps) x=x;
else
{
len=l-r-x;
tt=len/vx;
if(s-tt<=eps) x=x+vx*s;
else
{
s=s-tt;
len=l-2*r;
tt=len/vx;
if(s-tt<=eps) x=l-r-vx*s;
else
{
s-=tt;
len=x-r;
tt=len/vx;
if(s-tt<=eps) x=r+vx*s;
}
}
}
return x;
}
double fun2(double x,double vx,double s,double r,double l)
{
if(vx==0) return x;
double c=2*(l-2*r);
double tt=c/vx;
while(s-tt>=0+eps) s-=tt;
double len;
if(s==0+eps) x=x;
else
{
len=x-r;
tt=len/vx;
if(s-tt<=eps) x=x-vx*s;
else
{
s=s-tt;
len=l-2*r;
tt=len/vx;
if(s-tt<=eps) x=r+vx*s;
else
{
s-=tt;
len=l-r-x;
tt=len/vx;
if(s-tt<=eps) x=l-r-vx*s;
}
}
}
return x;
}
int main()
{
//freopen("Input.txt","r",stdin);
double l,w,x,y,r,a,v,s;
while(~scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l,&w,&x,&y,&r,&a,&v,&s))
{
if(l<=0) break;
double a1=(a/180)*PI;
double vx=v*cos(a1);
double vy=v*sin(a1);
double xx,yy;
if(a>=0&&a<=90)
{
xx=fun1(x,vx,s,r,l);
yy=fun1(y,vy,s,r,w);
}
else if(a>90&&a<=180)
{
vx=vx<0?-vx:vx; vy=vy<0?-vy:vy;
yy=fun1(y,vy,s,r,w);
xx=fun2(x,vx,s,r,l);
}
else if(a>180&&a<=270)
{
vx=vx<0?-vx:vx; vy=vy<0?-vy:vy;
xx=fun2(x,vx,s,r,l);
yy=fun2(y,vy,s,r,w);
}
else
{
vx=vx<0?-vx:vx; vy=vy<0?-vy:vy;
xx=fun1(x,vx,s,r,l);
yy=fun2(y,vy,s,r,w);
}
printf("%.2lf %.2lf\n",xx,yy);
}
return 0;
}