Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <vector>
- using namespace std;
- struct tower {
- int x, y;
- };
- double y_at(tower a, tower b, int x) {
- double dx = b.x - a.x,
- dy = b.y - a.y;
- return (x - a.x) * (dy / dx) + a.y;
- }
- int main() {
- int n, m;
- cin >> n;
- vector<tower> a, b;
- for (int i = 0; i < n; i++) {
- tower t;
- cin >> t.x >> t.y;
- a.push_back(t);
- }
- cin >> m;
- for (int i = 0; i < m; i++) {
- tower t;
- cin >> t.x >> t.y;
- b.push_back(t);
- }
- for (int i = 0; i < m; i++) {
- double mcy = -1.0;
- for (int j = 0; j < n; j++) {
- double cy = b[i].y;
- int ax = min(a[j].x, b[i].x),
- bx = max(a[j].x, b[i].x);
- for (int k = 0; k < m; k++)
- if (b[k].x > ax && b[k].x < bx) {
- double ky = y_at(b[i], a[j], b[k].x);
- if (ky < b[k].y)
- cy = y_at(b[k], a[j], b[i].x);
- }
- if (mcy < 0.0 || cy < mcy)
- mcy = cy;
- }
- printf("%.2f\n", mcy - b[i].y);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment