TOYS
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 8661   Accepted: 4114

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

 
 
 
 
 
 
就是给了m个点,落在n+1个区域中,问各个区域有多少个点。
就是利用叉积去判断点在线段的哪一侧,可以二分去做,比较快。
 
/************************************************************
* Author : kuangbin
* Email : kuangbin2009@126.com
* Last modified : 2013-07-13 17:15
* Filename : POJ2318TOYS.cpp
* Description :
* *********************************************************/ #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <string>
#include <math.h> using namespace std;
struct Point
{
int x,y;
Point(){}
Point(int _x,int _y)
{
x = _x;y = _y;
}
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
int operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
int operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
};
struct Line
{
Point s,e;
Line(){}
Line(Point _s,Point _e)
{
s = _s;e = _e;
}
}; int xmult(Point p0,Point p1,Point p2) //计算p0p1 X p0p2
{
return (p1-p0)^(p2-p0);
}
const int MAXN = ;
Line line[MAXN];
int ans[MAXN];
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n,m,x1,y1,x2,y2;
bool first = true;
while(scanf("%d",&n) == && n)
{
if(first)first = false;
else printf("\n");
scanf("%d%d%d%d%d",&m,&x1,&y1,&x2,&y2);
int Ui,Li;
for(int i = ;i < n;i++)
{
scanf("%d%d",&Ui,&Li);
line[i] = Line(Point(Ui,y1),Point(Li,y2));
}
line[n] = Line(Point(x2,y1),Point(x2,y2));
int x,y;
Point p;
memset(ans,,sizeof(ans));
while( m-- )
{
scanf("%d%d",&x,&y);
p = Point(x,y);
int l = ,r = n;
int tmp;
while( l <= r)
{
int mid = (l + r)/;
if(xmult(p,line[mid].s,line[mid].e) < )
{
tmp = mid;
r = mid - ;
}
else l = mid + ;
}
ans[tmp]++;
}
for(int i = ; i <= n;i++)
printf("%d: %d\n",i,ans[i]);
}
return ;
}
 
 
 
 

POJ 2318 TOYS (计算几何,叉积判断)的更多相关文章

  1. POJ 2318 TOYS 利用叉积判断点在线段的那一侧

    题意:给定n(<=5000)条线段,把一个矩阵分成了n+1分了,有m个玩具,放在为位置是(x,y).现在要问第几个位置上有多少个玩具. 思路:叉积,线段p1p2,记玩具为p0,那么如果(p1p2 ...

  2. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  3. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  4. POJ 2318 TOYS【叉积+二分】

    今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...

  5. POJ 2318 TOYS (叉乘判断)

    <题目链接> 题目大意: 给出矩形4个点和n个挡板俩顶点的位置,这n个挡板将该矩形分成 n+1块区域,再给你m个点的坐标,然你输出每个区域内有几个点. 解题思路: 用叉乘即可简单判断点与直 ...

  6. poj 2318 TOYS(计算几何 点与线段的关系)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12015   Accepted: 5792 Description ...

  7. POJ 2318 TOYS(计算几何)

    跨产品的利用率推断点线段向左或向右,然后你可以2分钟 代码: #include <cstdio> #include <cstring> #include <algorit ...

  8. TOYS - POJ 2318(计算几何,叉积判断)

    题目大意:给你一个矩形的左上角和右下角的坐标,然后这个矩形有 N 个隔板分割成 N+1 个区域,下面有 M 组坐标,求出来每个区域包含的坐标数.   分析:做的第一道计算几何题目....使用叉积判断方 ...

  9. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  10. POJ 2318 TOYS (叉积+二分)

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

随机推荐

  1. [反汇编练习] 160个CrackMe之024

    [反汇编练习] 160个CrackMe之024. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...

  2. HDU 5264 pog loves szh I (字符串,水)

    题意:设有两个串A和B,现将B反转,再用插入的形式合成一个串.如:A:abc   B:efg:反转B先,变gfe:作插入,agbfce.现在给出一个串,要求还原出A和B. 思路:扫一遍O(n),串A在 ...

  3. 用 Xcode 开发 Cydia Substrate 插件(二)

    上次介绍了一个如何用 Xcode 来构建 Substrate 插件,但是开发的具体过程还没有涉及,而这往往又正是初学者最难下手的地方,所以有了本文的后续. 不过在开始之前你要先做好思想准备,相比较开发 ...

  4. php flock注意事项

    对于实际的运用,必须将其添加到所有使用的文件脚本中 但注意:其函数无法再NFS或其他网络文件系统中使用也无法在多线程服务器API中使用.

  5. Heritrix源码分析(六) Heritrix的文件结构分析(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/642618      本博客已迁移到本人独立博客: http://www.yun5u. ...

  6. 前端程序员:月薪 5K 到 5 万,我干了啥(转)

    转自:http://www.imooc.com/article/4110 前端程序员:月薪 5K 到 5 万,我干了啥前端开发工作已经变的越来越复杂,仅仅是想罗列一份前端开发的学习列表就已经是一件艰巨 ...

  7. MySQL基础之第16章 数据备份与还原

    16.1.数据备份 16.1.1.使用 mysqldump 命令备份 mysqldump [OPTIONS] database [tables]mysqldump [OPTIONS] --databa ...

  8. EL表达式(胖先生版)

    EL表达式没有指定范围,从最小范围开始 <% pageContext.setAttribute("shxt", "java web"); request. ...

  9. 小结JS中的OOP(中)

    此篇文章主要是提炼<JavaScript高级程序设计>中第六章的一些内容. 一:JS中OOP相关的概念 开始之前先总结JS中OOP相关的一些概念: 构造函数:JS中的构造函数就是普通的函数 ...

  10. nginx上传目录配置,禁止执行权限

    我们经常会把网站的图片文件上传目录设置为只可上传文件但不能执行文件,就是要禁止执行权限,小编来给大家举一个上传目录配置,禁止执行权限方法,各位可参考. 如果不让有执行权限最简单的办法  代码如下 复制 ...