当前位置:码农谷 > 算法与程序 > HDU 5114 Collision:题目解答源码

HDU 5114 Collision:题目解答源码

所属学科:C语言 - 结构体与共用体 难度: 关注度:77

Matt is playing a naive computer game with his deeply loved pure girl.      

The playground is a rectangle with walls around. Two balls are put in different positions inside the rectangle. The balls are so tiny that their volume can be ignored. Initially, two balls will move with velocity (1, 1). When a ball collides with any side of the rectangle, it will rebound without loss of energy. The rebound follows the law of refiection (i.e. the angle at which the ball is incident on the wall equals the angle at which it is reflected).      

After they choose the initial position, Matt wants you to tell him where will the two balls collide for the first time.      

输入描述

The first line contains only one integer T which indicates the number of test cases.      

For each test case, the first line contains two integers x and y. The four vertices of the rectangle are (0, 0), (x, 0), (0, y) and (x, y). (1 ≤ x, y ≤ 10 5)      

�The next line contains four integers x 1, y 1, x 2, y 2. The initial position of the two balls is (x 1, y 1) and (x 2, y 2). (0 ≤ x 1, x 2 ≤ x; 0 ≤ y 1, y 2 ≤ y)

输出描述

For each test case, output “Case #x:” in the first line, where x is the case number (starting from 1).      

In the second line, output “Collision will not happen.” (without quotes) if the collision will never happen. Otherwise, output two real numbers x c and y c, rounded to one decimal place, which indicate the position where the two balls will first collide.

程序源码

完整的源代码如下

#include "iostream"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "algorithm"
using namespace std;
int n,m;
int MIN(int x,int y)
{
    if (x<y) return x;
    return y;
}
int main()
{
    int x1,y1,x2,y2,t,ii,i,j,k,fx11,fx12,fx21,fx22,move,x1o,x2o,y1o,y2o;
    double ansx,ansy;

    scanf("%d",&t);
    for (ii=1;ii0||x1==0&&fx110||y1==0&&fx120||x2==0&&fx210||y2==0&&fx22<0) fx22=-fx22;

关注微信,获得更多免费资源
关于我们   |   免责声明   |   联系我们   |   网站地图   |   HR交流群   |   学生交流群   |   教师交流群

码农谷   版权所有 © 2015-2017   湘ICP备16018319号-1