这道题和POJ 2318几乎是一样的。
区别就是输入中坐标不给排序了,=_=||
输出变成了,有多少个区域中有t个点。
1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 7 struct Point 8 { 9 int x, y; 10 Point(int x=0, int y=0):x(x), y(y) {} 11 }; 12 typedef Point Vector; 13 14 Point read_point() 15 { 16 int x, y; 17 scanf("%d%d", &x, &y); 18 return Point(x, y); 19 } 20 21 Point operator + (const Point& A, const Point& B) 22 { return Point(A.x+B.x, A.y+B.y); } 23 24 Point operator - (const Point& A, const Point& B) 25 { return Point(A.x-B.x, A.y-B.y); } 26 27 int Cross(const Point& A, const Point& B) 28 { return A.x*B.y - A.y*B.x; } 29 30 const int maxn = 5000 + 10; 31 int up[maxn], down[maxn], ans[maxn]; 32 int n, m; 33 Point A0, B0; 34 35 int binary_search(const Point& P) 36 { 37 int L = 0, R = n; 38 while(L < R) 39 { 40 int mid = L + (R - L + 1) / 2; 41 Point A(down[mid], B0.y), B(up[mid], A0.y); 42 Vector v1 = B - A; 43 Vector v2 = P - A; 44 if(Cross(v1, v2) < 0) L = mid; 45 else R = mid - 1; 46 } 47 return L; 48 } 49 50 int main() 51 { 52 //freopen("in.txt", "r", stdin); 53 54 while(scanf("%d", &n) == 1 && n) 55 { 56 memset(ans, 0, sizeof(ans)); 57 58 scanf("%d", &m); A0 = read_point(); B0 = read_point(); 59 for(int i = 1; i <= n; ++i) scanf("%d%d", &up[i], &down[i]); 60 sort(up + 1, up + 1 + n); sort(down + 1, down + 1 + n); 61 for(int i = 0; i < m; ++i) 62 { 63 Point P; P = read_point(); 64 int pos = binary_search(P); 65 ans[pos]++; 66 } 67 sort(ans, ans + n + 1); 68 69 puts("Box"); 70 int i; 71 for(i = 0; i <= n; ++i) if(ans[i]) break; 72 while(i <= n) 73 { 74 int cnt = 1; 75 int num = ans[i]; 76 while(i <= n && ans[i+1] == ans[i]) { i++; cnt++; } 77 i++; 78 printf("%d: %d\n", num, cnt); 79 } 80 } 81 82 return 0; 83 }