POJ 2398 Toy Storage POJ2318提高版入门题
在poj 2318的基础上 加上一个排序(因为板的坐标不是有序的),再加多一个统计就好了。
View Code
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; struct point { int x, y; }; struct node { int up, down; }date[1007]; int n, m; point toy[1007]; point a, b; int ans[1007], cnt[1007]; int cross(point o, point a, point b) { return ((a.x-o.x)*(b.y-o.y)-(a.y-o.y)*(b.x-o.x)); } int find(point key) { int l , r, mid; l = 0; r = n+1; point upp, downn; upp.y = a.y; downn.y = b. y; while(l <= r) { mid = (l + r) >> 1; upp.x = date[mid].up; downn.x = date[mid].down; if(cross(downn, upp, key) > 0 ) r = mid - 1; else l = mid + 1; } return l; } bool cmp(node a, node b) { return a.up<b.up; } int main() { int i, j; while( ~scanf("%d", &n) && n) { scanf("%d", &m); scanf("%d%d%d%d",&a.x, &a.y, &b.x, &b.y); date[0].up = date[0].down = a.x; date[n+1].up = date[n+1].down = b.x; for(i = 1; i <= n; i++) scanf("%d%d",&date[i].up, &date[i].down); sort(date+1, date+n+1, cmp); memset(ans, 0, sizeof(ans)); memset(cnt, 0, sizeof(cnt)); for(i=1;i<=m;i++) { scanf("%d%d", &toy[i].x, &toy[i].y); int index = find(toy[i]); ans[index-1]++; } printf("Box\n"); for(i=0;i<=n;i++) if(ans[i])cnt[ans[i]]++; for(i=0;i<=n;i++) if(cnt[i])printf("%d: %d\n",i, cnt[i]); } return 0; }


浙公网安备 33010602011771号