和poj2318是姐妹篇吧~~~ 这个题需要排序,排成poj2318那种的,然后统计下就好。
具体题意详见2318 http://blog.csdn.net/zxy_snow/archive/2011/04/19/6334800.aspx
#include <queue> #include <stack> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <iostream> #include <limits.h> #include <string.h> #include <algorithm> using namespace std; const int MAX = 1010; struct SEG{ int x1,y1,x2,y2; }; SEG s[MAX]; struct point{ int x,y; }; point toy[MAX]; int sum[MAX]; int crossProduct(point a,point b,point c)//向量 ac 在 ab 的方向 { return (c.x - a.x)*(b.y - a.y) - (b.x - a.x)*(c.y - a.y); } bool inBox(point t,SEG ls,SEG rs) { point a,b,c,d; a.x = ls.x1; a.y = ls.y1; b.x = ls.x2; b.y = ls.y2; c.x = rs.x2; c.y = rs.y2; d.x = rs.x1; d.y = rs.y1; if( crossProduct(b,t,c) >= 0 && crossProduct(c,t,d) >= 0 && crossProduct(d,t,a) >= 0 && crossProduct(a,t,b) >= 0 ) return true; return false; } bool cmp(SEG a,SEG b) { double mina = min(a.x1,a.x2); double minb = min(b.x1,b.x2); if( mina == minb ) return max(a.x1,a.x2) < max(b.x1,b.x2); return mina < minb; } int t[1010]; int main() { int n,m,x1,y1,x2,y2,a,b; while( ~scanf("%d",&n) && n ) { memset(sum,0,sizeof(sum)); scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2); s[0].x1 = x1; s[0].y1 = y1; s[0].x2 = x1; s[0].y2 = y2; for(int i=1; i<=n; i++) { scanf("%d %d",&a,&b); s[i].x1 = a; s[i].y1 = y1; s[i].x2 = b; s[i].y2 = y2; } n++; s[n].x1 = x2; s[n].y1 = y1; s[n].x2 = x2; s[n].y2 = y2; sort(s,s+n+1,cmp); for(int i=0; i<m; i++) scanf("%d %d",&toy[i].x,&toy[i].y); for(int i=0; i<m; i++) for(int k=0; k<n; k++) if( inBox(toy[i],s[k],s[k+1]) ) { sum[k]++; break; } memset(t,0,sizeof(t)); for(int i=0; i<n; i++) if( sum[i] ) t[sum[i]]++; printf("Box/n"); for(int i=0; i<n; i++) if( t[i] ) printf("%d: %d/n",i,t[i]); } return 0; }