zoukankan      html  css  js  c++  java
  • TOYS POJ

    原题链接

    • 题解:普通小模拟。也学到了一些东西,所有的几何题,如果可以整数,那就用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
    ", i, cnt[i]);
            }
        }
    }
    signed main() {
        int t = 1;  // scanf("%d", &t);
        while (t--) {
            solve();
        }
        return 0;
    }
    
  • 相关阅读:
    (转)TweenMax动画库学习(三)
    (转)TweenMax动画库学习(二)
    (转)TweenMax动画库学习(一)
    深入剖析Java中的装箱与拆箱(转)
    Spring MVC 和 Spring 总结(转)
    react native for android(ajax)
    React Native HelloWorld
    C# JMAIL发送邮件
    C# 接收邮件
    Spring Mvc Mybatis(初次学习)
  • 原文地址:https://www.cnblogs.com/Xiao-yan/p/14639614.html
Copyright © 2011-2022 走看看