HDU 5114 Collision
Collision
Time Limit: 15000/15000 MS (Java/Others) Memory Limit: 512000/512000 K (Java/Others)
Total Submission(s): 864 Accepted Submission(s): 206
Problem Description
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.
Input
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 ≤ 105)
The next line contains four integers x1, y1, x2, y2. The initial position of the two balls is (x1, y1) and (x2, y2). (0 ≤ x1, x2 ≤ x; 0 ≤ y1, y2 ≤ y)
Output
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 xc and yc, rounded to one decimal place, which indicate the position where the two balls will first collide.
Sample Input
3
10 10
1 1 9 9
10 10
0 5 5 10
10 10
1 0 1 10
Sample Output
Case #1:
6.0 6.0
Case #2:
Collision will not happen.
Case #3:
6.0 5.0
Hint
In first example, two balls move from (1, 1) and (9, 9) both with velocity (1, 1), the ball starts from (9, 9) will rebound at point (10, 10) then move with velocity (−1, −1). The two balls will meet each other at (6, 6).
Source
2014ACM/ICPC亚洲区北京站-重现赛(感谢北师和上交)
解析:扩展欧几里得。参考[http://www.cnblogs.com/TenderRun/p/5943453.html](http://www.cnblogs.com/TenderRun/p/5943453.html)。
```
#include
typedef long long ll;
ll ta,tb,x,y, time;
int T,n,m,x1,y1,x2,y2;
ll extgcd(ll a, ll b, ll &x, ll &y)
{
if(b == 0){
x = 1;
y = 0;
return a;
}
ll q = extgcd(b, a%b, y, x);
y -= a/b*x;
return q;
}
int main()
{
int cn = 0;
scanf("%d",&T);
while(T--){
scanf("%d%d%d%d%d%d", &n, &m, &x1, &y1, &x2, &y2);
n = 2 ;m = 2; x1 = 2; y1 = 2; x2 = 2; y2 = 2;
ta = n-(x1+x2)/2; tb = m-(y1+y2)/2;
printf("Case #%d:\n",++cn);
time = -1;
if(x1 == x2 && y1 == y2) time = 0;
else if(y1y2) time = ta;
else if(x1x2) time = tb;
else{
ll d = extgcd(n,m,x,y);
if((tb-ta)%d==0){
x = (tb-ta)/dx;
x = (x%(m/d)+m/d)%(m/d);
time = ta+nx;
}
}
if(time == -1)
puts("Collision will not happen.");
else{
x1 = (x1+time)%(2n); y1 = (y1+ time)%(2m);
if(x1>n) x1 = 2n-x1;
if(y1>m) y1 = 2m-y1;
printf("%.1f %.1f\n", x1/2.0, y1/2.0);
}
}
return 0;
}
HDU 5114 Collision的更多相关文章
- 数学(扩展欧几里得算法):HDU 5114 Collision
Matt is playing a naive computer game with his deeply loved pure girl. The playground is a rectangle ...
- HDU 4793 Collision(2013长沙区域赛现场赛C题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4793 解题报告:在一个平面上有一个圆形medal,半径为Rm,圆心为(0,0),同时有一个圆形范围圆心 ...
- HDU 4793 Collision (2013长沙现场赛,简单计算几何)
Collision Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 5114 扩展欧几里得
题目大意:给你两个球的坐标 他们都往(1, 1)这个方向以相同的速度走,问你他们在哪个位置碰撞. 思路:这种题目需要把x方向和y方向分开来算周期,两个不同周期需要用扩展欧几里得来求第一次相遇. #in ...
- HDU 4793 Collision (解二元一次方程) -2013 ICPC长沙赛区现场赛
题目链接 题目大意 :有一个圆硬币半径为r,初始位置为x,y,速度矢量为vx,vy,有一个圆形区域(圆心在原点)半径为R,还有一个圆盘(圆心在原点)半径为Rm (Rm < R),圆盘固定不动,硬 ...
- HDU 4793 Collision --解方程
题意: 给一个圆盘,圆心为(0,0),半径为Rm, 然后给一个圆形区域,圆心同此圆盘,半径为R(R>Rm),一枚硬币(圆形),圆心为(x,y),半径为r,一定在圆形区域外面,速度向量为(vx,v ...
- 2014ACM/ICPC亚洲区北京站题解
本题解不包括个人觉得太水的题(J题本人偷懒没做). 个人觉得这场其实HDU-5116要比HDU-5118难,不过赛场情况似乎不是这样.怀疑是因为老司机带错了路. 这套题,个人感觉动态规划和数论是两个主 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing 数学
C. Ray Tracing 题目连接: http://codeforces.com/contest/724/problem/C Description oThere are k sensors lo ...
随机推荐
- mac os 下如何清除/切换svn eclipse插件的用户
以mac os x为例(Unix/Linux类似), 1.打开命令行窗口,即用户的根目录(用户的home目录) $ ls -al ... drwxr-xr-x 6 linxyz staff ...
- POJ 2912 Rochambeau(难,好题,枚举+带权并查集)
下面的是从该网站上copy过来的,稍微改了一点,给出链接:http://hi.baidu.com/nondes/item/26dd0f1a02b1e0ef5f53b1c7 题意:有N个人玩剪刀石头布, ...
- POJ 1731
#include<iostream> #include<string> #include<algorithm> using namespace std; int m ...
- C#委托及事件
转载:http://www.cnblogs.com/warensoft/archive/2010/03/19/1689806.html C#委托及事件 在C#中,委托(delegate)是一种引用类型 ...
- 转: 在.NET中操作数字证书
作者:玄魂出处:博客2010-06-23 12:05 http://winsystem.ctocio.com.cn/19/9492019.shtml .NET为我们提供了操作数字证书的两个主要的类,分 ...
- 简单的线程同步问题:两个线程交替执行N次【Synchronized、Lock、ArrayBlockingQueue】
方法一:传统的线程方法import org.apache.log4j.Logger; /** * 两个线程执行的代码片段要实现同步互斥的效果,它们必须用同一个Lock对象.<br/> * ...
- java教材
教材blog !!http://www.w3cschool.cc/java/java-tutorial.html ok http://www.douban.com/group/topic/ ...
- 简单的算法题, Find Minimum in Rotated Sorted Array 的Python实现。
简单的算法题, Find Minimum in Rotated Sorted Array 的Python实现. 题目: Suppose a sorted array is rotated at som ...
- PHP Redis 集群封装类
<?php /** * Redis 操作,支持 Master/Slave 的负载集群 * * @author V哥 */ class RedisCluster{ // 是否 ...
- JAVA文件中获取路径及WEB应用程序获取路径方法
JAVA文件中获取路径及WEB应用程序获取路径方法 1. 基本概念的理解 `绝对路径`:你应用上的文件或目录在硬盘上真正的路径,如:URL.物理路径 例如: c:/xyz/test.txt代表了tes ...