其他分享
首页 > 其他分享> > TOYS POJ - 2318

TOYS POJ - 2318

作者:互联网

原题链接

#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;
}

标签:ld,return,2318,Point,int,pos,POJ,TOYS,include
来源: https://www.cnblogs.com/Xiao-yan/p/14639614.html