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. USACO December 铂金Maxflow

    USACO 2015 December Contest, Platinum Problem 1. Max Flow Farmer John has installed a new system of ...

  2. Django(命名URL和URL反向解析)

    day67 参考: https://www.cnblogs.com/liwenzhou/articles/8271147.html#autoid-1-4-0 反向解析URL             本 ...

  3. Spring 扫描标签<context:component-scan/>

    一. <context:annotation-config/> 此标签支持一些注入属性的注解, 列如:@Autowired, @Resource注解 二. <context:comp ...

  4. Linux上安装java JDK

    yum方式 1.查看yum中的各个版本 yum -y list java* 2.选择一个版本安装(如1.7) yum -y install java-1.7.0-openjdk* 3.安装完成后可查看 ...

  5. log4j的日志级别(ssm中log4j的配置)

    log4j定义了8个级别的log(除去OFF和ALL,可以说分为6个级别),优先级从高到低依次为:OFF.FATAL.ERROR.WARN.INFO.DEBUG.TRACE. ALL. 1. ALL ...

  6. [LeetCode]640解方程式

    问题描述: 示例 1: 输入: "x+5-3+x=6+x-2" 输出: "x=2" 示例 2: 输入: "x=x" 输出: "In ...

  7. 性能优化中CPU、内存、磁盘IO、网络性能的依赖(转)

    关于系统性能优化,推荐一篇不错的博客! 系统优化是一项复杂.繁琐.长期的工作,优化前需要监测.采集.测试.评估,优化后也需要测试.采集.评估.监测,而且是一个长期和持续的过程,不 是说现在优化了,测试 ...

  8. C# 多线程六之Task(任务)三之任务工厂

    1.知识回顾,简要概述 前面两篇关于Task的随笔,C# 多线程五之Task(任务)一 和 C# 多线程六之Task(任务)二,介绍了关于Task的一些基本的用法,以及一些使用的要点,如果都看懂了,本 ...

  9. Android 开发服务类 05_ ApkPatchDemo

    APP 增量更新服务端[https://github.com/cundong/SmartAppUpdates] import com.cundong.common.Constants; import ...

  10. tomcat如何正确的开启远程调试功能

    在日常开发中,有时需要对远程服务器上的应用进行远程调试,对于tomcat,要进行远程调试其实很简单,只需要在启动tomcat时开启jpda服务即可. 什么是JPDA呢? JPDA(JavaPlatfo ...