TOYS

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 16222   Accepted: 7779

Description

Calculate the number of toys that land in each bin of a partitioned toy box. 
Mom and dad have a problem - their child John never puts his toys away when he is finished playing with them. They gave John a rectangular box to put his toys in, but John 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 John to find his favorite toys.

John's parents came up with the following idea. They put cardboard partitions into the box. Even if John keeps throwing his toys into the box, at least toys that get thrown into different bins stay separated. The following diagram shows a top view of an example toy box. 
 
For this problem, you are asked to determine how many toys fall into each partition as John throws them into the toy box.

Input

The input file contains one or more problems. The first line of a problem consists of six integers, n m x1 y1 x2 y2. The number of cardboard partitions is n (0 < n <= 5000) and the number of toys is m (0 < m <= 5000). 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 contain two integers per line, Ui Li, indicating that the ends of the i-th cardboard partition is at the coordinates (Ui,y1) and (Li,y2). You may assume that the cardboard partitions do not intersect each other and that they are specified in sorted order from left to right. The next m lines contain two integers per line, Xj Yj specifying where the j-th toy has landed in the box. The order of the toy locations is random. You may assume that no toy will land exactly on a cardboard partition or outside the boundary of the box. The input is terminated by a line consisting of a single 0.

Output

The output for each problem will be one line for each separate bin in the toy box. For each bin, print its bin number, followed by a colon and one space, followed by the number of toys thrown into that bin. Bins are numbered from 0 (the leftmost bin) to n (the rightmost bin). Separate the output of different problems by a single blank line.

Sample Input

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

Sample Output

0: 2
1: 1
2: 1
3: 1
4: 0
5: 1 0: 2
1: 2
2: 2
3: 2
4: 2

Hint

As the example illustrates, toys that fall on the boundary of the box are "in" the box.

Source

 
对于每个玩具,二分找到其左边第一条直线,由此得到对应区域。
 //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];
int n, m; bool check(int id, int x, int y){
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("inputA.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));
int x, y;
for(int i = ; i < m; i++){
cin>>x>>y;
ans[get_position(x, y)]++;
}
for(int i = ; i <= n; i++)
cout<<i<<": "<<ans[i]<<endl;
cout<<endl;
} return ;
}

POJ2318(KB13-A 计算几何)的更多相关文章

  1. POJ-2318 TOYS 计算几何 判断点在线段的位置

    题目链接:https://cn.vjudge.net/problem/POJ-2318 题意 在一个矩形内,给出n-1条线段,把矩形分成n快四边形 问某些点在那个四边形内 思路 二分+判断点与位置关系 ...

  2. 计算几何——点线关系(叉积)poj2318

    #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> #i ...

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

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

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

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

  5. POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage

    题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...

  6. poj2318(叉积判断点在直线左右+二分)

    题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...

  7. HDU 2202 计算几何

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

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

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

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

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

随机推荐

  1. SQL 将一列多行数据合并为一行

    原表数据: 期望结果: 使用STUFF + FOR XML PATH即可实现以上效果 执行以下SQL: , , '') AS Course FROM Student AS T 可以看到输出结果与期望结 ...

  2. SpringBoot配置文件application.properties详解

    喜欢的朋友可以关注下,粉丝也缺. 相信很多的码友在接触springboot时,不知道怎么去配置一些项目中需要的配置,比如数据源,tomcat调优,端口等等,下面我就给大家奉献出一些项目中常用的配置信息 ...

  3. Python(28)---模块和包的基本概念

    一.模块 定义:在python中,一个 .py 文件就称为一个模块 使用模块的好处:最大的好处就是提高了代码的可维护性 分类(三种): python标准库 第三方模块 应用程序自定义模块 模块导入方法 ...

  4. Python文件与函数练习题

    练习题 文件处理相关 编码问题 请说明python2 与python3中的默认编码是什么? python2默认是ASCII码,python3默认是utf-8 为什么会出现中文乱码?你能列举出现乱码的情 ...

  5. odoo开发笔记--字段追踪,消息通知机制

    odoo有着强大的消息记录.通知机制: 实际开发中,常常会有客户的需求,页面上form视图中的某些字段不允许反复修改, 假如有的用户修改了,恶意搞坏,往往容易给公司利益造成损失,或破坏,那么如何有效的 ...

  6. MySQL命令行登陆,远程登陆MySQL

    注: MySQL图形界面管理工具[navicat 10.1.8中文绿色版] 下载地址:http://www.t00y.com/file/18393836 备用地址:http://ProCircle.q ...

  7. 鼠标右键添加"在此处打开命令窗口"

    从windows7开始,提供了一个便于从当前文件夹打开cmd命令行窗口的快捷方式: 直接使用  Shift+鼠标右键==>“在此处打开命令行窗口” 有可能以后会遇到的问题,可参考如下.. htt ...

  8. idea 运行scala代码 报错:Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$ java.lang.NoClassDefFoundError: scala/Function0 Error: A JNI error has occurred, please check your installati

    各种报错信息如下: java.lang.NoClassDefFoundError: scala/Function0 at java.lang.Class.getDeclaredMethods0(Nat ...

  9. spring-如何将spring源码成功导入Eclipse中

    一.从 github上下载Spring源码到本机 二.利用 Gradle 编译 Spring 源码 环境: - Spring源码版本:spring-framework-4.3.x - Gradle版本 ...

  10. VS2013编译的exe独立运行在XP中方案

    转载知乎 现在,我们深入探讨一下:<如何使用VS 2013发布一个可以在Windows XP中独立运行的可执行文件>. 这个问题是比较常见且容易造成初学者困惑的,作为曾经撞了无数次南墙的初 ...