3018 问题 C: Elastic Ball in the Frame

问题 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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值