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. [ionic开源项目教程] - 第10讲 新闻详情页的用户体验优化

    目录 [ionic开源项目教程] 第1讲 前言,技术储备,环境搭建,常用命令 [ionic开源项目教程] 第2讲 新建项目,架构页面,配置app.js和controllers.js [ionic开源项 ...

  2. django - from django.db.models import F - class F

    F() 的执行不经过 python解释器,不经过本机内存,是生成 SQL语句的执行. # Tintin filed a news story! reporter = Reporters.objects ...

  3. 【JavaScript学习笔记】点击消失

    <!DOCTYPE html> <html> <head> <script type="text/javascript" src=&quo ...

  4. 每天一个Linux命令(2): ls

    ls命令是linux下最常用的命令.ls命令就是list的缩写缺省下ls用来打印出当前目录的清单如果ls指定其他目录那么就会显示指定目录里的文件及文件夹清单. 通过ls 命令不仅可以查看linu ...

  5. php的session.serialize_handler

    php里面的session.serialize_handler用来设置php的session的序列化方式,默认值为php,及使用php的序列化与反序列化. 还有一个值为session.serializ ...

  6. 【英语】Bingo口语笔记(29) - Run系列

  7. 【英语】Bingo口语笔记(43) - u长短音

  8. gcc/交叉编译

    一.gcc编译的情况: 1.linux gcc包含的c/c++编译器,gcc和cc是一样的,c++和g++是一样的,一般c程序就用gcc编译,c++程序就用g++编译. 2.linux gcc的应用: ...

  9. Java条件语句之 switch

    当需要对选项进行等值判断时,使用 switch 语句更加简洁明了.例如:根据考试的名次,给予前 4 名不同的奖品.第一名,奖励笔记本一台:第二名,奖励 IPAD 2 一个:第三名,奖励移动电源一个:最 ...

  10. Java并发编程-volatile

    一. volatite 简述Java 语言提供了一种稍弱的同步机制,即 volatile 变量.用来确保将变量的更新操作通知到其他线程,保证了新值能立即同步到主内存,以及每次使用前立即从主内存刷新. ...