The calculation of the geometry of the part is relatively simple, the focus is that the two points a little trouble (Daniel ignore), every time you write two points you have to use a pen to simulate, and then to determine.
Because the y1,y2 is public, it is only possible to store x coordinates when the segment is stored. Then the judgment is on the right or the left.
#include <cstdio> #include <cstring> #include <algorithm> #include <vector>using namespace std; const int n=5005;struct line{int x1,x2;} Line[n];int x1,x2,y1,y2,n,m,num[n];int judge (int x,int y,int ID) {int a1=line[id].x1-x,a2=line[id].x2-x; int b1=y1-y,b2=y2-y; return A1*B2-A2*B1;} int main () {int x,y,k=0; while (scanf ("%d", &n), n!=0) {scanf ("%d%d%d%d%d", &m,&x1,&y1,&x2,&y2); for (int i=1;i<=n;i++) scanf ("%d%d", &line[i].x1,&line[i].x2); memset (num,0,sizeof (num)); for (int i=1;i<=m;i++) {scanf ("%d%d", &x,&y); if (judge (x,y,1) <0)///here to pay attention to {num[0]++; Continue if (judge (x,y,n) >0)///Here also note that through drawing can be found, here need to discuss separately. {num[n]++; Continue } int l=1,r=n;//Here is a two-point while (r-l>1) {int mid= (L +R)/2; if (judge (X,y,mid) <0) R=mid; else L=mid; } num[l]++; } if (k>0) printf ("\ n"); k++; for (int i=0;i<=n;i++) printf ("%d:%d\n", I,num[i]); } return 0;}
POJ 2318 TOYS