POJ 2318 TOYS (computational geometry)

Source: Internet
Author: User

Cross-product utilization inferred point segments left or right, and then you can 2 minutes

Code:

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int N = 5005;int N, m,    x1, y1, x2, y2;struct Point {int x, y;        Point () {}-point (int x, int y) {this->x = x;    This->y = y; }};typedef Point Vector; Vector operator-(vector A, vector B) {return vector (a.x-b.x, a.y-b.y);}    struct Seg {point A, B;        SEG () {} seg (point A, point B) {this->a = A;    This->b = b; }} seg[n];int ans[n];int cross (vector A, vector B) {return a.x * b.y-a.y * b.x;}    void Gao (point p) {int L = 0, r = N;        while (L < r) {int mid = (L + r)/2;        if (Cross (seg[mid].a-p, seg[mid].b-p) < 0) R = Mid;    else L = mid + 1; } ans[l]++;}        int main () {while (~SCANF ("%d", &n) && N) {memset (ans, 0, sizeof (ans));        scanf ("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);        int x, y; for (int i = 0; i < n; i++) {scanf ("%d%d", &x, &y);        Seg[i] = Seg (Point (X, y1), point (Y, y2));            } for (int i = 0; i < m; i++) {scanf ("%d%d", &x, &y);        Gao (Point (x, y));        } for (int i = 0; I <= N; i++) printf ("%d:%d\n", I, ans[i]);    printf ("\ n"); } return 0;}


POJ 2318 TOYS (computational geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.