题目链接:http://poj.org/problem?id=2398
思路RT,和POJ2318一样,就是需要排序,输出也不一样。手工画一下就明白了。注意叉乘的时候a×b是判断a在b的顺时针还是逆时针侧,>0是顺时针测,<0是逆时针侧,本题对应看成右、左侧,特别注意。
1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <fstream> 24 #include <cassert> 25 #include <cstdio> 26 #include <bitset> 27 #include <vector> 28 #include <deque> 29 #include <queue> 30 #include <stack> 31 #include <ctime> 32 #include <set> 33 #include <map> 34 #include <cmath> 35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rll(a) scanf("%lld", &a) 44 #define Rs(a) scanf("%s", a) 45 #define Cin(a) cin >> a 46 #define FRead() freopen("in", "r", stdin) 47 #define FWrite() freopen("out", "w", stdout) 48 #define Rep(i, len) for(int i = 0; i < (len); i++) 49 #define For(i, a, len) for(int i = (a); i < (len); i++) 50 #define Cls(a) memset((a), 0, sizeof(a)) 51 #define Clr(a, x) memset((a), (x), sizeof(a)) 52 #define Full(a) memset((a), 0x7f7f, sizeof(a)) 53 #define lrt rt << 1 54 #define rrt rt << 1 | 1 55 #define pi 3.14159265359 56 #define RT return 57 #define lowbit(x) x & (-x) 58 #define onenum(x) __builtin_popcount(x) 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef map<string, int> msi; 65 typedef vector<int> vi; 66 typedef vector<LL> vl; 67 typedef vector<vl> vvl; 68 typedef vector<bool> vb; 69 70 typedef struct Point { 71 int x, y; 72 Point() {} 73 Point(int xx, int yy) : x(xx), y(yy) {} 74 bool operator==(Point p) { 75 return x == p.x && y == p.y; 76 } 77 bool operator<(Point p) { 78 if(x == p.x) return y < p.y; 79 return x < p.x; 80 } 81 }Point; 82 typedef struct Line { 83 Point a, b; 84 Line() {} 85 Line(Point aa, Point bb) : a(aa), b(bb) {} 86 }Line; 87 const int maxn = 5050; 88 const int maxm = 5050; 89 Line line[maxn]; 90 Point s, e; 91 int n, m; 92 int tmp[maxm]; 93 int ans[maxm]; 94 95 int ok(Point p, Line l) { 96 RT ((l.b.y-l.a.y)*(p.x-l.a.x)-(p.y-l.a.y)*(l.b.x-l.a.x)); 97 } 98 99 bool cmp(Line a, Line b) { 100 if(a.a == b.a) return a.b < b.b; 101 return a.a < b.a; 102 } 103 104 int main() { 105 // FRead(); 106 int x1, x2; 107 bool flag = 1; 108 while(~Rint(n) && n) { 109 Cls(tmp); Cls(ans); 110 Rint(m); Rint(s.x); Rint(s.y); Rint(e.x); Rint(e.y); 111 Rep(i, n) { 112 Rint(x1); Rint(x2); 113 line[i] = Line(Point(x1, s.y), Point(x2, e.y)); 114 } 115 line[n] = Line(Point(e.x, s.y), e); 116 Point p; 117 sort(line, line+n+1, cmp); 118 W(m) { 119 Rint(p.x); Rint(p.y); 120 int l = 0, r = n; 121 int ret; 122 while(l <= r) { 123 int m = (l + r) >> 1; 124 if(ok(p, line[m]) > 0) { 125 ret = m; 126 r = m - 1; 127 } 128 else l = m + 1; 129 } 130 tmp[ret]++; 131 } 132 int hi = 0; 133 Rep(i, n+1) { 134 hi = max(hi, tmp[i]); 135 ans[tmp[i]]++; 136 } 137 printf("Box "); 138 For(i, 1, hi+1) { 139 if(ans[i]) printf("%d: %d ", i, ans[i]); 140 } 141 } 142 RT 0; 143 }