Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4243   Accepted: 2517

Description

Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing with them. They gave Reza a rectangular box to put his toys in. Unfortunately, Reza is rebellious and obeys his parents by simply throwing his toys into the box. All the toys get mixed up, and it is impossible for Reza to find his favorite toys anymore.
Reza's parents came up with the following idea. They put cardboard
partitions into the box. Even if Reza keeps throwing his toys into the
box, at least toys that get thrown into different partitions stay
separate. The box looks like this from the top:



We want for each positive integer t, such that there exists a partition with t toys, determine how many partitions have t, toys.

Input

The
input consists of a number of cases. The first line consists of six
integers n, m, x1, y1, x2, y2. The number of cardboards to form the
partitions is n (0 < n <= 1000) and the number of toys is given in
m (0 < m <= 1000). The coordinates of the upper-left corner and
the lower-right corner of the box are (x1, y1) and (x2, y2),
respectively. The following n lines each consists of two integers Ui Li,
indicating that the ends of the ith cardboard is at the coordinates
(Ui, y1) and (Li, y2). You may assume that the cardboards do not
intersect with each other. The next m lines each consists of two
integers Xi Yi specifying where the ith toy has landed in the box. You
may assume that no toy will land on a cardboard.

A line consisting of a single 0 terminates the input.

Output

For
each box, first provide a header stating "Box" on a line of its own.
After that, there will be one line of output per count (t > 0) of
toys in a partition. The value t will be followed by a colon and a
space, followed the number of partitions containing t toys. Output will
be sorted in ascending order of t for each box.

Sample Input

4 10 0 10 100 0
20 20
80 80
60 60
40 40
5 10
15 10
95 10
25 10
65 10
75 10
35 10
45 10
55 10
85 10
5 6 0 10 60 0
4 3
15 30
3 1
6 8
10 10
2 1
2 8
1 5
5 5
40 10
7 9
0

Sample Output

Box
2: 5
Box
1: 4
2: 1

Source

/**
题意:给一个区域的左上和右上坐标,然后给出区域中的n条边,然后,给出m个玩具的坐标;
但是没有排序,要求比如说是有一个玩具的区域的个数
做法:计算几何
**/
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string.h>
#include<stdio.h>
#define maxn 5000 + 10
using namespace std;
int n,m;
int mmap[maxn];
int mmpp[maxn];
const double eps = 1e-;
const double PI = acos(-1.0);
struct Point
{
double x;
double y;
Point(){}
Point(double _x,double _y)
{
x = _x;
y = _y;
}
Point operator - (const Point &b) const
{
return Point(x - b.x,y - b.y);
}
double operator ^(const Point &b) const
{
return x*b.y - y*b.x;
}
double operator *(const Point &b) const
{
return x*b.x + y*b.y;
}
}point[maxn];
struct Line
{
Point s;
Point e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;
e = _e;
}
}line[maxn];
bool cmp(Line a,Line b)
{
return a.s.x < b.s.x;
}
int mul(Point a,Point b,Point c)
{
return (b - a) ^(c - a);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif // ONLINE_JUDGE
int x1,y1,x2,y2;
while(~scanf("%d",&n))
{
if(n == ) break;
memset(mmap,,sizeof(mmap));
memset(mmpp,,sizeof(mmpp));
scanf("%d %d %d %d %d",&m,&x1,&y1,&x2,&y2);
int u,l;
for(int i=;i<n;i++)
{
scanf("%d %d",&u,&l);
line[i] = Line(Point(u,y1),Point(l,y2));
}
line[n] = Line(Point(x2,y1),Point(x2,y2));
sort(line,line+n+,cmp);
int x,y;
for(int i=;i<m;i++)
{
scanf("%d %d",&x,&y);
Point pp = Point(x,y);
int left = ;
int right = n;
int tmp = ;
while(left <= right)
{
int mid = (left + right) >>;
if(mul(pp,line[mid].s,line[mid].e)<)
{
tmp = mid;
right = mid-;
}
else left = mid+;
}
mmap[tmp] ++;
}
int mmax = ;
for(int i=;i<=n;i++)
{
mmpp[i] = ;
}
for(int i=;i<=n;i++)
{
if(mmap[i]>) mmpp[mmap[i]] ++;
}
printf("Box\n");
for(int i=;i<=n;i++)
{
if(mmpp[i]>) printf("%d: %d\n",i,mmpp[i]);
}
}
return ;
}

POJ-2398的更多相关文章

  1. POJ 2398 - Toy Storage 点与直线位置关系

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5439   Accepted: 3234 Descr ...

  2. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  3. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  4. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  5. poj 2398 Toy Storage(计算几何)

    题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...

  6. poj 2398 (叉积+二分)

    http://poj.org/problem?id=2398 Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  7. POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]

    题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...

  8. POJ 2398 Toy Storage(计算几何,叉积判断点和线段的关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3146   Accepted: 1798 Descr ...

  9. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  10. POJ 2398 Toy Storage

    这道题和POJ 2318几乎是一样的. 区别就是输入中坐标不给排序了,=_=|| 输出变成了,有多少个区域中有t个点. #include <cstdio> #include <cma ...

随机推荐

  1. CC DGCD:Dynamic GCD——题解

    https://vjudge.net/problem/CodeChef-DGCD https://www.codechef.com/problems/DGCD 题目大意: 给一颗带点权的树,两个操作: ...

  2. nodejs获取文件信息,判断是文件或目录

    var stat = fs.statSync(filename); console.log(stat) 输出 { dev: 0, ino: 0, mode: 33206, nlink: 1, uid: ...

  3. HDU3265 线段树(扫描线)

    Posters Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

  4. [LeetCode] 递推思想的美妙 Best Time to Buy and Sell Stock I, II, III O(n) 解法

    题记:在求最大最小值的类似题目中,递推思想的奇妙之处,在于递推过程也就是比较求值的过程,从而做到一次遍历得到结果. LeetCode 上面的这三道题最能展现递推思想的美丽之处了. 题1 Best Ti ...

  5. LightOJ 1093 - Ghajini 线段树

    http://www.lightoj.com/volume_showproblem.php?problem=1093 题意:给定序列,问长度为d的区间最大值和最小值得差最大是多少. 思路:可以使用线段 ...

  6. js 拖动滑块验证

    备注:拖动滑块时尽量平移,chrome浏览器上没有卡顿情况,但是搜狗极速模式和360极速模式都遇到了卡顿,拖不动情况,应是浏览器内部对事件响应速度导致吧. JS代码: ;(function ($,wi ...

  7. Android蓝牙通信总结

    这篇文章要达到的目标: 1.介绍在Android系统上实现蓝牙通信的过程中涉及到的概念. 2.在android系统上实现蓝牙通信的步骤. 3.在代码实现上的考虑. 4.例子代码实现(手持设备和蓝牙串口 ...

  8. bzoj 2730: [HNOI2012]矿场搭建——tarjan求点双

    Description 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出口,使得无论哪一 ...

  9. 牛客网刷题(纯java题型 31~60题)

    牛客网刷题(纯java题型 31~60题) 重写Override应该满足"三同一大一小"三同:方法名相同,参数列表相同,返回值相同或者子类的返回值是父类的子类(这一点是经过验证的) ...

  10. R、Python、Scala和Java,到底该使用哪一种大数据编程语言?

    有一个大数据项目,你知道问题领域(problem domain),也知道使用什么基础设施,甚至可能已决定使用哪种框架来处理所有这些数据,但是有一个决定迟迟未能做出:我该选择哪种语言?(或者可能更有针对 ...