题目链接:http://poj.org/problem?id=2398

Time Limit: 1000MS Memory Limit: 65536K

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

与POJ 2318几乎一模一样的题。

POJ 2318的题解:http://www.cnblogs.com/dilthey/p/7767218.html

由于本题输入cardboard的时候是乱序,所以在二分前需要sort一下;另外输出的方式和2318不太一样,改一下即可。

AC代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#define MAX 5005
#define M_PI 3.14159265358979323846 //POJ的math头文件好像没有这个定义
using namespace std; const double eps = 1e-; struct Point{
double x,y;
Point(double tx=,double ty=):x(tx),y(ty){}
};
typedef Point Vctor; Vctor operator + (Vctor A,Vctor B){return Vctor(A.x+B.x,A.y+B.y);}
Vctor operator - (Point A,Point B){return Vctor(A.x-B.x,A.y-B.y);}
Vctor operator * (Vctor A,double p){return Vctor(A.x*p,A.y*p);}
Vctor operator / (Vctor A,double p){return Vctor(A.x/p,A.y/p);}
bool operator < (Point A,Point B){return A.x < B.x || (A.x == B.x && A.y < B.y);} struct Line{
Point p;
Vctor v;
Line(Point p=Point(0,0),Vctor v=Vctor(,)):p(p),v(v){}
Point point(double t){return p + v*t;} //获得直线上的距离p点t个单位长度的点
}; double Cross(Vctor A,Vctor B){return A.x*B.y-A.y*B.x;} int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return (x<)?(-):();
}
bool operator == (Point A,Point B){return dcmp(A.x-B.x)== && dcmp(A.y-B.y)==;} int n,m;
Point upper_left,lower_right;
Line x_axis;//下边界
Line cardboard[MAX];//隔板
Point toy;
int area[MAX],cnt[MAX];//记录每个区域的 int Left_of_Line(Line l,Point p)
{
if(Cross(l.v,p-l.p)>) return ;//左边
else return ;
}
int where(Point toy)
{
int l=,r=n+;
while(r-l>)
{
int mid=(l+r)/;
if(Left_of_Line(cardboard[mid],toy)) r=mid;
else l=mid;
}
return l;
} bool cmp(Line a,Line b)
{
if(a.p==b.p) return (a.p+a.v)<(b.p+b.v);
else return a.p<b.p;
}
int main()
{
while(scanf("%d",&n) && n!=)
{
scanf("%d%lf%lf%lf%lf",&m,&upper_left.x,&upper_left.y,&lower_right.x,&lower_right.y); x_axis=Line(lower_right,Vctor(-,));
cardboard[]=Line(Point(upper_left.x,lower_right.y),Vctor(,)), cardboard[n+]=Line(lower_right,Vctor(,)); Point U=Point(,upper_left.y),L=Point(,lower_right.y);
for(int i=;i<=n;i++)
{
scanf("%lf%lf",&U.x,&L.x);
cardboard[i]=Line(L,U-L);
}
sort(cardboard+,cardboard+n+,cmp); memset(area,,sizeof(area));
for(int i=;i<=m;i++)
{
scanf("%lf%lf",&toy.x,&toy.y);
area[where(toy)]++;
}
memset(cnt,,sizeof(cnt));
for(int i=;i<=n;i++) cnt[area[i]]++;
printf("Box\n");
for(int i=;i<=m;i++)
{
if(cnt[i]==) continue;
printf("%d: %d\n",i,cnt[i]);
}
}
}

POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. poj 2398 Toy Storage(计算几何 点线关系)

    Toy Storage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4588   Accepted: 2718 Descr ...

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

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

  9. 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)

    Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...

随机推荐

  1. ios开发之--armv7,armv7s,arm64,i386,x86_64详解

    有时候在运行的时候,经常出现诸如i386的错误,最新一些可能会出现 No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch ...

  2. PDF XSS

    漏洞测试: 下面,我们介绍如何把 JavaScript 嵌入到 PDF 文档之中.我使用的是迅捷 PDF 编辑器未注册版本 1.启动迅捷 PDF 编辑器打开一个 PDF 文件,或者使用“创建 PDF ...

  3. RF-For循环使用

    场景1:

  4. JavaWeb学习总结(十六)Cookie保存中文内容

    Cookie的值保存中文内容,可以使用Java.net.URLDecoder进行解码. 示例: <%@page import="java.net.URLDecoder"%&g ...

  5. 如何构建日均千万PV Web站点 (三) Sharding

    其实国内许多大型网站为了应对日益复杂的业务场景,通过使用分而治之的手段将整个网站业务分成不同的产品线,比如说国内那些大型购物交易网站它们都将自己的网站首页.商铺.订单.买家.卖家等拆分不同的产品线,分 ...

  6. N76E003的定时器/计数器 0和1

    定时器/计数器 0和1N76E003系列定时器/计数器 0和1是2个16位定时器/计数器.每个都是由两个8位的寄存器组成的16位计数寄存器. 对于定时器/计数器0,高8位寄存器是TH0. 低8位寄存器 ...

  7. 在 Core Data 中存取 transformable 类型的数据

    本文转载至 http://imenjoe.com/2015/04/10/CoreData-transformable-20150410/ 在开发过程中有一个需要在 Core Data 中存取 NSDi ...

  8. 使用kendynet编写网关服务

    网游服务器大多提供了网关服务,用于作为用户和内部服务器组之间通信代理.网关服务一方面将用户消息从客户端分发到正确的内部服务器. 另一方面将来自内部服务器的数据包转发给客户端.一般对于网关应用来说,压力 ...

  9. .net 将DLL程序集生成到指定目录中

    .在程序集右键属性 .在程序集属性界面中找到生成事件 在预先生成事件命令行添加: IF NOT EXIST "$(ProjectDir)..\Bin" MD "$(Pro ...

  10. 批量更改数据库表架构(生成sql后直接执行!)

    批量更改数据库表架构(生成sql后直接执行!) use my_test; --当前数据库 ), ), ), @NewSql VARCHAR(max), @Index INT; SET @SchemaO ...