题目链接:POJ 2398 Toy Storage
几何,跟上道题差不多的,只是这道题的输入是没有排序的栅栏。上道题偷懒不想写边的结构体,把一条边的两个点拆成了两个点i和i+n,代码直接用到了这道题上,然后排序只排了前一半,然后就是一直错也找不到bug。。唉唉唉不能偷懒啊。。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const double eps = 1e-10;
const int MAX_N = 5000 + 10;
struct Point
{
int x, y;
Point(int x=0, int y=0):x(x),y(y) { }
};
struct Line
{
Point a, b;
};
typedef Point Vector;
Vector operator + (const Vector& A, const Vector& B)
{
return Vector(A.x+B.x, A.y+B.y);
}
Vector operator - (const Point& A, const Point& B)
{
return Vector(A.x-B.x, A.y-B.y);
}
Vector operator * (const Vector& A, double p)
{
return Vector(A.x*p, A.y*p);
}
bool operator < (const Point& a, const Point& b)
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
int dcmp(double x)
{
if(fabs(x) < eps)
return 0;
else
return x < 0 ? -1 : 1;
}
bool operator == (const Point& a, const Point &b)
{
return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0;
}
int Cross(const Vector& A, const Vector& B)
{
return A.x*B.y - A.y*B.x;
}
//Point p[MAX_N << 1];
Line l[MAX_N];
Point bound[3];
Point toy;
int _count[MAX_N];
int n, m;
bool cmp(Line q, Line w)
{
if(q.a.x != w.a.x)
return q.a.x < w.a.x;
else
return q.a.y < q.b.y;
}
void b_search()
{
int ll = 0, r = n - 1, mid;
while(ll <= r)
{
mid = (ll + r) >> 1;
if(Cross(toy - l[mid].a, l[mid].b - l[mid].a) > 0)
r = mid - 1;
else if(Cross(toy - l[mid].a, l[mid].b - l[mid].a) < 0)
ll = mid + 1;
}
_count[r + 1]++;
}
int _size[MAX_N];
int main()
{
//freopen("in.txt", "r", stdin);
while(scanf("%d", &n), n)
{
memset(_count, 0, sizeof(_count));
memset(_size, 0, sizeof(_size));
scanf("%d", &m);
scanf("%d%d%d%d", &bound[0].x, &bound[0].y, &bound[2].x, &bound[2].y);
for(int i = 0; i < n; i++)
{
scanf("%d%d",&l[i].a.x, &l[i].b.x);
l[i].a.y = bound[0].y;
l[i].b.y = bound[2].y;
}
sort(l, l + n, cmp);
for(int i = 0; i < m; i++)
{
scanf("%d%d", &toy.x, &toy.y);
b_search();
}
int _max = 0;
for(int i = 0; i <= n; i++)
{
_size[_count[i]]++;
_max = max(_max, _count[i]);
}
printf("Box\n");
for(int i = 1; i <= _max; i++)
{
if(_size[i] != 0)
printf("%d: %d\n", i, _size[i]);
}
}
return 0;
}