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. 【文文殿下】[APIO2010]特别行动队 题解

    基本上是一个斜率优化裸题了 #include<bits/stdc++.h> using namespace std; typedef long long ll; const int max ...

  2. 定位 和 z-index

    三.定位 定位有三种:(1) 相对定位.(2) 绝对定位.(3) 固定定位 1.相对定位(相对于自己原来的位置定位) 现象和使用: a.如果对当前元素仅仅设置了相对定位,那么与标准流的盒子没什么区别: ...

  3. windows下的redis集群搭建的艰辛历程

    我是参照这两篇教程进行的操作:   1.https://www.cnblogs.com/weiqinl/p/6490372.html   (主) 2.https://blog.csdn.net/qiu ...

  4. SpringBoot从入门到逆天(1)

    1.SpringBoot是什么? <1>为Sping开发提供一个更 快捷更广泛的入门体验. <2>开箱即用,不合适时特可以快速抛弃. <3>提供一系列大型项目常用的 ...

  5. XAMPP中MySQL无法启动解决办法

    如图 问题出在mysql的路径上,其实报错已经讲得听清楚了 预期应该是这样 结果却是这样 所以解决办法当然就是修改这个路径,出现这个报错原因大多因为之前电脑装过mysql,所以电脑默认启动是原来的my ...

  6. android自定义控件 几种方式总结

    方式1:不继承任何组件 , 直接在代码里面调用实例化.public class ProgressDialog { private Dialog dialog; public ProgressDialo ...

  7. Spring4 mvc+maven 框架搭建(2)

    在上一篇博客中,数据库数据和mybatis相关的java代码已经生成,接下来就可以使用IDE工具来搭建框架了. 在这里,我使用maven构建和管理代码,使用jdk1.8环境. 首先打开Eclipse, ...

  8. Jfinal QuartzPlugin 简单使用案例

    之前一直使用spring quartz感觉还挺好用的,就想着jfinal是不是也可以使用quartz插件,于是发现了QuartzPlugin和jfinal-scheduler<参考:https: ...

  9. 第一个WCF程序

    WCF的服务需要寄宿在进程中,我们把服务端的叫做宿主,为服务指定宿主指定的过程叫服务寄宿.有两种方式一种是自我寄宿(Self-Hosting),一种是IIS寄宿方式.Self-Hosting我们通过一 ...

  10. Android _关于fragment切换重新加载的解决分享给大家

    在项目中需要进行Fragment的切换,一直都是用replace()方法来替换Fragment但是,这样会有一个问题 ,应该很多朋友都遇到过:每次切换的时候,Fragment都会重新实例化,也就是运行 ...