POJ 3218 TOYS (computational geometry) (two points)

Source: Internet
Author: User
Tags min printf

toys:http://poj.org/problem?id=2318

To give you a box, there are n panels separated into n+1 parts, give you the coordinates of the M toy, ask each part has several toys.

Train of thought: to each toy, the two-segment subscript, judge the toy in the left or right side of the line, enumerated after statistics.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

#include <map> #include <stack> #include <queue> #include <math.h> #include <stdio.h> #inc Lude <stdlib.h> #include <string.h> #include <iostream> #include <limits.h> #include < Algorithm> #define LL long #define MAX (A,B) ((a) > (b)? ( A):(b) #define MIN (a,b) ((a) < (b)? ( A):(B) #define MAX3 (A, B, c) (A>b?max (A, C): Max (b, c)) #define MIN3 (A, B, c) (A<b?min (A, c): Min (b, c)) #define Max4 (A, B, C, D) Max (Max (A, B), Max (C, D)) #define MIN4 (A, B, C, D) min (min (A, b), Min (c, D)) #define EPS 1e-9 #define INF 1 &
  
lt;< using namespace std;
int n, m;
  
int cnt[5010]; struct point {int x, y;}
  
P struct Node {point A, B;}
  
LINE[5010];
  
int Location (Point A, point B, point C) {return (a.x-c.x) * (B.Y-C.Y)-(b.x-c.x) * (A.Y-C.Y);}
    void Binary_search (point A, int n) {int L, r, Mid;
    L = 0;
    R = n-1;
        while (L < r) {mid = (l+r) >>1; if (Location (A, LINE[MID].A, LINE[MID].B) > 0) {l = mid+1;
        else {r = Mid;
    } if (Location (A, line[l].a, line[l].b) < 0) {cnt[l]++;
    else {cnt[l+1]++;
    } void Solve () {int x1, x2, y1, y2, T1, T2;
        while (~SCANF ("%d", &n) && N) {memset (CNT, 0, sizeof (CNT));
        scanf ("%d%d%d%d%d", &m, &x1, &y1, &x2, &y2);
            for (int i = 0; i < n; ++i) {scanf ("%d%d", &t1, &AMP;T2);
            line[i].a.x = T1;
            LINE[I].A.Y = y1;
            line[i].b.x = T2;
        Line[i].b.y = y2;
            for (int i = 0; i < m ++i) {scanf ("%d%d", &p.x, &AMP;P.Y);
        Binary_search (P, N);
        for (int i = 0; I <= N; ++i) {printf ("%d:%d\n", I, cnt[i]);
    printf ("\ n"); int main (void) {freopen ("data.in", "R", stdin);
    Freopen ("Data.out", "w", stdout);
  
    Solve ();
return 0; }

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.