uva 11657 - Rational Billiard(数学)
2014-08-04 10:02
387 查看
题目链接:uva 11657 - Rational Billiard
题目大意:给定一个边界M,N,以及第一个球和第二个球的位置,第一个球以p,q的方向移动,碰到边界后被反弹,和光线的路线一致,问有没有可能集中第二个球。
解题思路:在网上参考别人的思路,首先将横纵坐标扩大相应倍数,保证p,q每移动一次对应在新平面为单位长度,然后只需要考虑横向移动所需要的步数,减掉纵向移动所需的步数后,剩余的步数是否满足周期的倍数即可。考虑四种请况。这题数据非常水,一开始坐标写错也过了。
题目大意:给定一个边界M,N,以及第一个球和第二个球的位置,第一个球以p,q的方向移动,碰到边界后被反弹,和光线的路线一致,问有没有可能集中第二个球。
解题思路:在网上参考别人的思路,首先将横纵坐标扩大相应倍数,保证p,q每移动一次对应在新平面为单位长度,然后只需要考虑横向移动所需要的步数,减掉纵向移动所需的步数后,剩余的步数是否满足周期的倍数即可。考虑四种请况。这题数据非常水,一开始坐标写错也过了。
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long ll; ll m, n, x0, y0, x1, y1, p, q; ll gcd (ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } bool judge () { if (p == 0 || q == 0) { ll u = p * (y1-y0) - q * (x1-x0); return u == 0; } ll absq = q < 0 ? -q : q; ll absp = p < 0 ? -p : p; m *= absq; x0 *= absq; x1 *= absq; n *= absp; y0 *= absp; y1 *= absp; p /= absp; q /= absq; ll d1 = q * (y1-y0) - p * (x1-x0); ll d2 = q * (y1-y0) - p * (2*m-x1-x0); ll d3 = q * (2*n-y1-y0) - p * (x1-x0); ll d4 = q * (2*n-y1-y0) - p * (2*m-x1-x0); ll g = gcd(2*m, 2*n); if (d1 % g == 0) return true; if (d2 % g == 0) return true; if (d3 % g == 0) return true; if (d4 % g == 0) return true; return false; } int main () { while (scanf("%lld%lld%lld%lld%lld%lld%lld%lld", &m, &n, &x0, &y0, &x1, &y1, &p, &q) == 8) { if (!(m || n || x0 || y0 || x1 || y1 || p || q)) break; printf("%s\n", judge() ? "HIT" : "MISS"); } return 0; }
相关文章推荐
- uva 10387 Billiard (基础数学问题.平面反射)
- uva573(数学)
- UVA 11461 - Square Numbers 数学水题
- UVa 11752 The Super Powers (数学)
- UVA 10387 Billiard
- UVa1388 - Graveyard (数学,思维)
- UVA - 10916 Factstone Benchmark(数学)
- UVa 10916 Factstone Benchmark (数学&阶乘的处理技巧)
- uva 1069 - Always an integer(数学+暴力)
- uva 10706 Number Sequence(数学)
- UVA, 332 Rational Numbers from Repeating Fractions
- POJ1320 UVA138 Street Numbers【Pell方程+数学】
- UVA913 Joana and the Odd Numbers【数学】
- UVA 10976 Fractions Again?(枚举+数学)
- 数学专项number_theory:UVa 756
- Uva11300(数学)
- UVA253 Cube painting(数学)
- uva 10387 Billiard
- UVa 679 - Dropping Balls 数学分析
- uva 10790(数学)