TOYS
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 16042   Accepted: 7688

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

[Submit]   [Go Back]   [Status]   [Discuss]

Home Page   Go Back  To top

这道题是我为数不多的能想出思路来的题,

它给的隔板都是排好序的

所以我们可以二分一个答案,

然后判断这个点在中点的哪个地方,

注意在这个地方有一个小技巧,

我们可以把点看成向量的相对向量,,,

大概就是这个意思,不是特别严谨,

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN=;
inline void read(int &n)
{
char c=getchar();bool flag=;n=;
while(c<''||c>'') c=='-'?flag=,c=getchar():c=getchar();
while(c>=''&&c<='') n=n*+(c-),c=getchar();if(flag==)n=-n;
}
int n,m,x1,yy1,x2,y2;
struct node
{
int x,y;
}point[MAXN];
struct Line
{
node a,b;
}line[MAXN];
int cross(node a,node b,node c)
{
return (c.x-a.x)*(c.y-b.y)-(c.x-b.x)*(c.y-a.y);
}
int ans[MAXN];
void calc(int num)
{
int l=,r=n-;
while(l<r)
{
int mid=(l+r)>>;
if(cross(point[num],line[mid].a,line[mid].b)>) l=mid+;
else r=mid;
}
if(cross(point[num],line[l].a,line[l].b)<)
ans[l]++;
else ans[l+]++; }
int main()
{
while(scanf("%d",&n)&&n)
{
scanf("%d%d%d%d%d",&m,&x1,&yy1,&x2,&y2);
for(int i=;i<n;i++)
{
int p,q;read(p);read(q);
line[i].a.x=p;
line[i].a.y=yy1;
line[i].b.x=q;
line[i].b.y=y2;
}
memset(ans,,sizeof(ans));
for(int i=;i<m;i++)
{
int p,q;read(p);read(q);
point[i].x=p;
point[i].y=q;
}
for(int i=;i<m;i++)
calc(i); for(int i=;i<=n;i++)
printf("%d: %d\n",i,ans[i]);
printf("\n");
}
return ;
}

POJ TOYS(叉积的妙用+二分答案)的更多相关文章

  1. POJ 1226 Substrings(后缀数组+二分答案)

    [题目链接] http://poj.org/problem?id=1226 [题目大意] 求在每个给出字符串中出现的最长子串的长度,字符串在出现的时候可以是倒置的. [题解] 我们将每个字符串倒置,用 ...

  2. poj 3294 Life Forms - 后缀数组 - 二分答案

    题目传送门 传送门I 传送门II 题目大意 给定$n$个串,询问所有出现在严格大于$\frac{n}{2}$个串的最长串.不存在输出'?' 用奇怪的字符把它们连接起来.然后求sa,hei,二分答案,按 ...

  3. poj 3415 Common Substrings - 后缀数组 - 二分答案 - 单调栈

    题目传送门 传送点I 传送点II 题目大意 给定串$A, B$,求$A$和$B$长度大于等于$k$的公共子串的数量. 根据常用套路,用一个奇怪的字符把$A$,$B$连接起来,然后二分答案,然后按mid ...

  4. Poj 1743 Musical Theme(后缀数组+二分答案)

    Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 28435 Accepted: 9604 Descri ...

  5. Poj 3261 Milk Patterns(后缀数组+二分答案)

    Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk g ...

  6. POJ 2018 Best Cow Fences (二分答案构造新权值 or 斜率优化)

    $ POJ~2018~Best~Cow~ Fences $(二分答案构造新权值) $ solution: $ 题目大意: 给定正整数数列 $ A $ ,求一个平均数最大的长度不小于 $ L $ 的子段 ...

  7. poj 1275 Cashier Employment - 差分约束 - 二分答案

    A supermarket in Tehran is open 24 hours a day every day and needs a number of cashiers to fit its n ...

  8. POJ 2018 Best Cow Fences(二分答案)

    题目链接:http://poj.org/problem?id=2018 题目给了一些农场,每个农场有一定数量的奶牛,农场依次排列,问选择至少连续排列F个农场的序列,使这些农场的奶牛平均数量最大,求最大 ...

  9. [poj 2773] Happy 2006 解题报告 (二分答案+容斥原理)

    题目链接:http://poj.org/problem?id=2773 题目大意: 给出两个数m,k,要求求出从1开始与m互质的第k个数 题解: #include<algorithm> # ...

随机推荐

  1. 1.RunLoop是什么?

    1.Run loops是线程相关的的基础框架的一部分. 一个run loop就是一个事件处理的循环.用来不停的调度工作以及处理输入事件.使用run loop的目的是让你的线程在有工作的时候忙于工作.而 ...

  2. Linux操作系统是如何工作的

    <实验五——Linux操作系统是如何工作的?破解操作系统的奥秘> 姓名:方超 学号:SA12**6201 Linux操作系统工作的基础 存储程序计算机.堆栈(函数调用堆栈)机制和中断机制是 ...

  3. 站点搭建从零開始(二)server空间

    前面介绍了域名相关知识.这里介绍server,也经常被叫做空间.也就是站点数据实际保存的地方. 1.整体介绍 依据国家相关规定,国内server空间须要进行备案.也就是到相关的机构进行登记.详细方法能 ...

  4. IBM AppScan官方帮助文档错别字缺陷,IBM的測试人员也太粗心了吧

    袁术=元素?

  5. Recovering unassigned shards on elasticsearch 2.x——副本shard可以设置replica为0在设置回来

    Recovering unassigned shards on elasticsearch 2.x 摘自:https://z0z0.me/recovering-unassigned-shards-on ...

  6. pgpool-II在故障切换过程中是如何选举新主节点的

    在pgpool的源代码中有有一个pgpool_main.c文件,在该文件中有一个pgpool的主函数pgpoolmain控制着pgpool的运行及相关操作. libpcp_ext.h文件中定义了pgp ...

  7. QNX多线程同步之Barrier(屏障)

    之前和大家介绍过QNX上的线程同步方法metux和semophore,通过这两种方法可以对一个或者几个资源进行加锁,避免资源使用上的冲突.在另一种情况下,某个线程需要在其它线程完成工作后才继续执行,这 ...

  8. C# 将string 转换为二维码图片,然后转为base64字符串编码 。

    需在nuget 添加此dll ///content字符串 public static string GetQRCode(string content, int moduleSize = 9) { va ...

  9. Hadoop_HDFS-基础知识摘要

    Hadoop典型应用有:搜索.日志处理.推荐系统.数据分析.视频图像分析.数据保存等.0.数据要首先分块 Block:将一个文件进行分块,通常是64M. NameNode:--管理节点保存整个文件系统 ...

  10. redis搭建与安装

    redis提供五种数据类型:string,hash,list,set及zset(sorted set). 第一部分:安装redis 希望将redis安装到此目录 1 /usr/local/redis ...