标签:with corn lower tps its stop input https this
http://codeforces.com/contest/982/problem/E
Consider a billiard table of rectangular size $n \times m$ with four pockets. Let‘s introduce a coordinate system with the origin at the lower left corner (see the picture).
There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that:
Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.
Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.
4 3 2 2 -1 1
0 0
给定一个球和方向,问能不能在盒子里停下来
Giving a ball and vector, judge it will stop in the box or not
如果您在平面上相对于其两侧对称地反射矩形,则球的新轨迹将更容易。线性轨迹如果是正确的。一个可能的解决方案是
If you symmetrically reflect a rectangle on the plane relative to its sides, the new trajectory of the ball will be much easier. Linear trajectory if be correct. One possible solution is:
#include <bits/stdc++.h>
using namespace std;
long long x, y, xx, yy;
long long vx, vy;
long long fx, fy;
long long c;
long long ex_gcd(long long a, long long b, long long &xa, long long &ya) {
if (!b) {
xa = c;
ya = 0;
return a;
}
long long ret = ex_gcd(b, a % b, xa, ya);
long long temp = xa;
xa = ya;
ya = temp - (a / b) * ya;
return ret;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cerr.tie(nullptr);
cin >> x >> y >> xx >> yy >> vx >> vy;
if (!vx) {
if (xx == 0 || xx == x) {
if (vy == 1) {
cout << xx << " " << y;
} else {
cout << xx << " " << 0;
}
} else
return 0 * puts("-1");
return 0;
}
if (!vy) {
if (yy == 0 || yy == y) {
if (vx == 1) {
cout << x << " " << yy;
} else {
cout << 0 << " " << yy;
}
} else
return 0 * puts("-1");
return 0;
}
if (vx == -1) fx = 1, xx = x - xx;
if (vy == -1) fy = 1, yy = y - yy;
c = xx - yy;
if (c % __gcd(x, y))
return 0 * puts("-1");
c /= __gcd(x, y);
long long m = y / __gcd(x, y);
long long xxx, yyy;
ex_gcd(x, y, xxx, yyy);
xxx = (xxx % m + m - 1) % m + 1;
yyy = -(yy - xx + x * xxx) / y;
long long ansn = x, ansm = y;
if (xxx % 2 == 0) ansn = x - ansn;
if (yyy % 2 == 0) ansm = y - ansm;
if (fx) ansn = x - ansn;
if (fy) ansm = y - ansm;
cout << ansn << " " << ansm;
}
Codeforces Codeforces Round #484 (Div. 2) E. Billiard
标签:with corn lower tps its stop input https this
原文地址:https://www.cnblogs.com/EDGsheryl/p/9175904.html