Toy Storage

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 5968   Accepted: 3573

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

 
与A题相同,但是线没有排序,询问的是有t个玩具的区域有几个
 //2017-08-30
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; const int N = ; struct Point{
int x, y;
Point(){}
Point(int _x, int _y):x(_x), y(_y){}
//a-b 表示向量 ba
Point operator- (const Point &b) const {
return Point(x-b.x, y-b.y);
}
//向量叉积
int operator* (const Point &b) const {
return x*b.y - y*b.x;
}
}A, B; int ans[N], U[N], L[N], t[N];
int n, m; bool check(int id, int x, int y){
if(y == A.y)return x > U[id];
if(y == B.y)return x > L[id];
Point a(L[id], B.y);
Point b(U[id], A.y);
Point c(x, y);
//令I = 向量ab 叉乘 向量 bc,若I为正,点c在向量ab的左侧(沿向量方向看);为负则在右侧
return ((c-a)*(b-a)) > ;
} int get_position(int x, int y){
int l = , r = n+, mid, ans;
while(l <= r){
mid = (l+r)>>;
if(check(mid, x, y)){
ans = mid;
l = mid+;
}else r = mid-;
}
return ans;
} int main()
{
std::ios::sync_with_stdio(false);
freopen("inputB.txt", "r", stdin);
while(cin>>n && n){
cin>>m>>A.x>>A.y>>B.x>>B.y;
U[] = L[] = A.x;
U[n+] = L[n+] = B.x;
for(int i = ; i <= n; i++)
cin>>U[i]>>L[i];
memset(ans, , sizeof(ans));
sort(U, U+n+);
sort(L, L+n+);
int x, y;
for(int i = ; i < m; i++){
cin>>x>>y;
ans[get_position(x, y)]++;
}
memset(t, , sizeof(t));
for(int i = ; i <= n; i++)
t[ans[i]]++;
cout<<"Box"<<endl;
for(int i = ; i <= m; i++)
if(t[i])
cout<<i<<": "<<t[i]<<endl;
} return ;
}

POJ2398(KB13-B 计算几何)的更多相关文章

  1. poj2398 Toy Storage 计算几何,叉积,二分

    poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...

  2. [POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)

    题目链接:http://poj.org/problem?id=2398 思路RT,和POJ2318一样,就是需要排序,输出也不一样.手工画一下就明白了.注意叉乘的时候a×b是判断a在b的顺时针还是逆时 ...

  3. poj2398计算几何叉积

    Mom and dad have a problem: their child, Reza, never puts his toys away when he is finished playing ...

  4. ACM/ICPC 之 计算几何入门-叉积-to left test(POJ2318-POJ2398)

    POJ2318 本题需要运用to left test不断判断点处于哪个分区,并统计分区的点个数(保证点不在边界和界外),用来做叉积入门题很合适 //计算几何-叉积入门题 //Time:157Ms Me ...

  5. HDU 2202 计算几何

    最大三角形 Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  6. ACM 计算几何中的精度问题(转)

    http://www.cnblogs.com/acsmile/archive/2011/05/09/2040918.html 计算几何头疼的地方一般在于代码量大和精度问题,代码量问题只要平时注意积累模 ...

  7. hdu 2393:Higher Math(计算几何,水题)

    Higher Math Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)

    Rescue The Princess Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Several days ago, a b ...

  9. [知识点]计算几何I——基础知识与多边形面积

    // 此博文为迁移而来,写于2015年4月9日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vxaq.html 1.前言 ...

随机推荐

  1. 前端基础-html 字体标签,排版标签,超链接,图片标签

    主要内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  2. 模拟ssh、黏包、hashlib模块

    一.模拟ssh 1.subprocess模块 ipconfig -all dir subprocess模块是python从2.4版本开始引入的模块.主要用来取代 一些旧的模块方法,如os.system ...

  3. sax解析xml,验证格式并支持自定义标签

    一.sax简介 SAX是事件驱动型的XML解析方式.顺序读取XML文件,生成事件,传播到用户定义的回调方法中来处理XML文件. 优点: 分段处理xml,而不是将整个xml一次加载进内存,内存占用少,速 ...

  4. MySQL 5.6不删空用户的影响

    目录 MySQL 5.6不删空用户的影响 问题 分析 测试 启动mysqld时没有加上--skip-name-resolve 启动mysqld时加上--skip-name-resolve 结论 MyS ...

  5. Vue + Bootstrap 制作炫酷个人简历(二)

    没想到隔了这么久才来更新. 用vue做简历,不是非常适合,为什么呢. 因为简历没什么数据上的操作,一般都是静态的内容. 不过都说了用Vue来做,也只能强行续命了. 这里是我做好的成品  非一般简历 由 ...

  6. 并发上下文控制包Context

    Context,是golang用来控制并发流程的库,它能方便的将主控程序的停止信号传递到goroutinue中,从而实现一键中止关联goroutinue的执行,除此之外,它还能将外部变量通过Value ...

  7. POJ 2551

    #include<iostream> #include<stdio.h> #include<string> using namespace std; //int m ...

  8. Vagrant安装Docker

    ======方法1=========== 一.vagrant安装centos 1.1 什么是vagrant: Vagrant是一个基于Ruby的工具,用于创建和部署虚拟化开发环境.它 使用Oracle ...

  9. 深入理解Spring的ImportSelector接口

    ImportSelector接口是至spring中导入外部配置的核心接口,在SpringBoot的自动化配置和@EnableXXX(功能性注解)都有它的存在,关于SpringBoot的分析可以参考:深 ...

  10. JavaScript -- Select

    -----053-Select.html----- <!DOCTYPE html> <html> <head> <meta http-equiv=" ...