TOYS POJ - 2318

原题链接

  • 题解:普通小模拟。也学到了一些东西,所有的几何题,如果可以整数,那就用int,实在是不行才用double
  • 代码:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;
typedef long long ld;
const int N = 5009;
const int M = 2 * N * N;
struct Point {
    ld x, y;
    Point(ld X = 0, ld Y = 0) { x = X, y = Y; }
    Point operator-(Point a) { return Point(x - a.x, y - a.y); }
    Point operator+(Point a) { return Point(x + a.x, y + a.y); }
    ld operator*(Point a) { return x * a.y - y * a.x; }
} lu, rd, up[N], down[N], toy[N];
typedef Point Vector;
int cnt[N];
int n, m;
bool check(int pos, int o) {
    Vector v1 = (up[pos] - down[pos]);
    Vector v2 = (toy[o] - down[pos]);
    return v2 * v1 > 0;
}
int find(int o) {
    int l = 1, r = n;
    while (l < r) {
        int mid = r + l >> 1;
        if (!check(mid, o)) {
            r = mid;
        } else
            l = mid + 1;
    }
    if (!check(l, o)) l--;
    return l;
}
void solve() {
    bool first = 1;
    while (~scanf("%d", &n)) {
        if (n == 0) return;
        if (!first)
        puts("");
        else first  =0;
        memset(cnt, 0, sizeof cnt);
        scanf("%d%lld%lld%lld%lld", &m, &lu.x, &lu.y, &rd.x, &rd.y);
        for (int i = 1; i <= n; i++) {
            ld x1, x2;
            scanf("%lld%lld", &x1, &x2);
            up[i] = {x1, lu.y};
            down[i] = {x2, rd.y};
        }
        for (int i = 1; i <= m; i++) {
            scanf("%lld%lld", &toy[i].x, &toy[i].y);
            cnt[find(i)]++;
        }
        for (int i = 0; i <= n; i++) {
            printf("%d: %d\n", i, cnt[i]);
        }
    }
}
signed main() {
    int t = 1;  // scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}
posted @ 2021-04-10 09:42  u_yan  阅读(26)  评论(0编辑  收藏  举报