码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2398 Toy Storage

时间:2015-02-02 12:30:51      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

这道题和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 }
代码君

 

POJ 2398 Toy Storage

标签:

原文地址:http://www.cnblogs.com/AOQNRMGYXLMV/p/4267393.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!