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, &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, &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; }