程序设计在线评测(Online Judge)


问题 1020. -- 2011市赛题:Fiber

1020: 2011市赛题:Fiber

时间限制: 1 Sec  内存限制: 128 MB
提交: 18  解决: 3
[提交][状态][讨论版]

题目描述

Today,here's a interesting problem.

Nowadays , optical fiber(光纤) is widely used in our life.Fiber Transmission (光纤传输) is the method to send  optical information (光信息)in a spacial pipe,as the figure shows.

The light goes into the pipe at the left end of the pipe,then after some times direct reflection,goes out the pipe at the right end , to send optical message.

Here's the problem, when the light goes into the pipe in a given direction ,which direction will it be when it goes out the pipe.

 

输入

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. (T <= 100)

Each test case start with two positive integers D , L , which indicate the diameter of pile and the lenth of the pipe.(that is to say the pipe is between Y = D , Y = 0,X = 0,and X = L).next lines follow three integers,h,Vx,Vy.represents the position and direction in which the light goes into the pipe,the position is (0,h) and the direction is vector (Vx,Vy). All numbers in the input is in the range of  int32.(D>= h>= 0,D > 0,L > 0,Vx > 0,Vy != 0.we ensure that the light can goes into the pipe in the given direction and position.)

输出

Output two integers Vx2 , Vy2 represent the direction vector in which the light goes out the pipe.because of the various way to present that direction,we need you make Abs(Vx) == Abs(Vx2).

样例输入

3
2 10
2 1 -1
2 11
2 1 -1
2 10
1 1 -1

样例输出

1 -1
1 1
1 1

提示

首先需要明确,射出时的方向一定是(Vx,Vy)或者(Vx,-Vy)

于是只要判断在管道内反射的次数是奇数次,或者偶数次即可.


因为方向和速度大小是无关的.可假设X方向速度为Vx.则在管道内的总时间为W /Vx,那么在Y方向上的总路程是L = W / Vx * Vy;则问题转化为从开始位置出发,结果L的路程,在Y方向上碰撞了几次.当然不用土土的模拟,只要判断L里有几个H就行了.当然要注意处理初试高度和一些边界情况.

来源

[提交][状态][讨论版]