问题 C: Elastic Ball in the Frame
时间限制: 2 Sec 内存限制: 64 MB
提交: 22 解决: 10
[提交][状态][讨论版]
题目描述
In a rectangular frame, there’s an elastic ball which can be regarded as a mass point(The ball can make elastic collisions with the frame).The frame lies on a smooth horizontal plane, and the initial position of the ball is at the lower left quarter(左下角)of the frame. Taking horizontal border as x axis and the vertical border as y axis, we can build the coordinate(坐标系). The position of the ball is (0,0).Given the ball’s initial speed, you are supposed to find its position at time t. (The collision trace of the ball forms a mirror reflection.)
输入
There is a positive integer n(n<1000) on the first line, representing the case number. There follows n lines, each line has 5 positive number, v(0
/*先算路程比先算速度精度高,分解向量*/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double PI = atan(1) * 4;
double getJourney(double journey, double l) {
int xCount;
xCount = (int)(journey / (l * 2));
journey = journey - xCount * l * 2;
if (journey > l) { //到边弹回来
journey = l - (journey - l);
}
return journey;
}
int main(int argc, char *argv[])
{
double x,v,degree,lx,ly,t,T,xJourney,ansY,yJourney,y,journey;
int xCount,yCount;
cin >> T;
while (T--) {
cin >> v >> degree >> ly >> lx >> t;
journey = t * v;
xJourney = journey * cos(degree * PI / 180); //分解为x方向的路程
xJourney = getJourney(xJourney, lx);
yJourney = sin(degree * PI / 180) * journey;
yJourney = getJourney(yJourney, ly);
printf("(%.2lf,%.2lf)\n", xJourney, yJourney);
}
return 0;
}