Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Cats & Rats equal-speed OX-line
- #include <bits/stdc++.h>
- using namespace std;
- typedef long double LD;
- typedef long long int LL;
- typedef pair <LL,LL> Point;
- #define X first
- #define Y second
- const int maxn = 2000;
- const LL inf = 1e18;
- LL a[maxn], b[maxn], s[maxn], e[maxn];
- LL secTime(Point A, Point B, Point C, Point D) {
- // Line AB represented as a1x + b1y = c1
- LD a1 = B.Y - A.Y, b1 = A.X - B.X;
- LD c1 = a1 * A.X + b1 * A.Y;
- // Line CD represented as a2x + b2y = c2
- LD a2 = D.Y - C.Y, b2 = C.X - D.X;
- LD c2 = a2 * C.X+ b2 * C.Y;
- LD makh = a1 * b2 - a2 * b1;
- LD sora = b2 * c1 - b1 * c2;
- LD ret = (2 * sora) / makh;
- LL upper = ret + 1e-9;
- return upper;
- }
- LL intersect(int i, int j) {
- if (max(a[i], b[i]) < min(b[j], a[j]) || max(a[j], b[j]) < min(b[i], a[i]))
- return inf;
- if (e[i] < s[j] || e[j] < s[i])
- return inf;
- if (a[i] < b[i] && a[j] < b[j]) {
- if (a[i] > a[j])
- swap(i, j);
- if (s[j] == s[i] + (a[j] - a[i]))
- return 2 * s[j];
- return inf;
- }
- if (a[i] > b[i] && a[j] > b[j]) {
- if (a[i] > a[j])
- swap(i, j);
- if (s[i] == s[j] + (a[j] - a[i]))
- return 2 * s[i];
- return inf;
- }
- Point A = make_pair(s[i], a[i]);
- Point B = make_pair(e[i], b[i]);
- Point C = make_pair(s[j], a[j]);
- Point D = make_pair(e[j], b[j]);
- LL ret = secTime(A, B, C, D);
- if (s[i] * 2 > ret || ret > e[i] * 2 || s[j] * 2 > ret || ret > e[j] * 2)
- return inf;
- return ret;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- int tc, n, m;
- cin >> tc;
- while (tc--) {
- cin >> n >> m;
- for (int i = 0; i < n; i++) {
- cin >> a[i] >> b[i] >> s[i];
- e[i] = s[i] + abs(b[i] - a[i]);
- }
- for (int i = n; i < n + m; i++) {
- cin >> a[i] >> b[i] >> s[i];
- e[i] = s[i] + abs(b[i] - a[i]);
- }
- for (int i = n; i < n + m; i++) {
- int idx = -1;
- LL mint = inf;
- for (int j = 0; j < n; j++)
- if (mint > intersect(i, j))
- mint = intersect(i, j), idx = j + 1;
- cout << idx << ' ';
- }
- cout << '\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement