来源 poj 2318

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.

用叉积的方法判断点在向量的左右边就可以了

int direction(point p1,point p2,point p3)//p1是向量起点,p2是终点,p3是判断点,>0则在左边<0在右侧

{

return (p1.x-p3.x)(p2.y-p3.y)-(p1.y-p3.y)(p2.x-p3.x);

}

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<stack>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
typedef long double ld;
typedef double db;
const ll mod=1e9+100;
const db e=exp(1);
const db eps=1e-8;
using namespace std;
const double pi=acos(-1.0);
const int inf=0xfffffff;
struct point
{
int x,y;
point(int a=0,int b=0)
{
x=a;y=b;
}
}t;
struct xl
{
point p1,p2;//p1是下面的点
int sum;
xl(int x=0,int y=0,int a=0,int b=0)
{
p1=point(x,y);
p2=point(a,b);sum=0;
}
}a[5005];
//bool cmp(xl a,xl b)
//{
// return a.p1.x<b.p1.x;
//}
int direction(point p1,point p2,point p3)//p1是向量起点,p2是终点,p3是判断点,》0则在左边<0在右侧
{
return (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x);
}
int main()
{
int n,m,X1,X2,Y1,Y2,x,y;
int jud=1;
while(1)
{
cin>>n;
if(!n)
return 0;
if(!jud)
pf("\n");
cin>>m>>X1>>Y1>>X2>>Y2;
rep(i,0,n)
{
cin>>x>>y;
a[i]=xl(y,Y2,x,Y1);
}
a[n]=xl();
// sort(a,a+n,cmp);
while(m--)
{
int temp=0;
cin>>t.x>>t.y;
rep(i,0,n)
{
if(direction(a[i].p1,a[i].p2,t)>0)
{
a[i].sum++;temp=1;
break;
}
}
if(!temp)
a[n].sum++;
}
rep(i,0,n+1)
{
pf("%d: %d\n",i,a[i].sum);
}
jud=0;
}
}

E - TOYS的更多相关文章

  1. 【POJ】2318 TOYS(计算几何基础+暴力)

    http://poj.org/problem?id=2318 第一次完全是$O(n^2)$的暴力为什么被卡了-QAQ(一定是常数太大了...) 后来排序了下点然后单调搞了搞..(然而还是可以随便造出让 ...

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

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

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

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

  4. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  5. poj 2318 TOYS

    TOYS 题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 思路:这道题很水,只是要知道会使用叉乘来表示点在线的上面还是下面: 当a ...

  6. 【POJ】2318 TOYS ——计算几何+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10281   Accepted: 4924 Description ...

  7. Codeforces Round #346 (Div. 2) C Tanya and Toys

    C. Tanya and Toys 题目链接http://codeforces.com/contest/659/problem/C Description In Berland recently a ...

  8. 2016NEFU集训第n+3场 G - Tanya and Toys

    Description In Berland recently a new collection of toys went on sale. This collection consists of 1 ...

  9. POJ2318 TOYS(叉积判断点与直线的关系+二分)

    Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...

  10. POJ2318 TOYS[叉积 二分]

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14433   Accepted: 6998 Description ...

随机推荐

  1. log4Net 高性能写入和CSV格式

    最近在使用log4net,在使用之前我们必须知道文件流是如何操作的,否则就是盲人摸向...,在FileAppender.cs文件里面有LockingModelBase来控制流的锁,默认有3个子类 Ex ...

  2. webservice-整理

    webservice-整理 RPC与WebService的区别:https://blog.csdn.net/defonds/article/details/71641634 http://www.di ...

  3. java类型生命周期

    开始阶段 装载:把二进制形式的java类型读入jvm中. 1)通过该类型的完全限定名,产生一个代表该类型的二进制数据流:2)解析这个二进制数据流为方法区内的内部数据结构:3)创建一个表示该类型的jav ...

  4. 【Linux】Cent OS 虚拟机开机自启动配置

    一次断电,导致实体机关机了,虚拟机也连不上去,只好手动来起来. 我想增加一下自启动,让硬件开机的时候,自动启动虚拟机: 其实是有办法的,尝试了一下,也成功了,这里简单标记下. virsh autost ...

  5. 如何将Ubuntu Server 12.04 升级到 Ubuntu Server 14.04 LTS

    升级Ubuntu 12.04到Ubuntu 14.04方法如下: 步骤一:在终端中运行下面的命令,它将安装所有的升级包.$ sudo apt-get update && sudo ap ...

  6. NeoFinder for Mac(增强型文件管理工具)破解版安装

    1.软件简介    NeoFinder 是 macOS 系统上一款帮助用户管理磁盘的 Mac 工具,NeoFinder for mac 能迅速组织您的数据,无论是在外部或内部磁盘,或任何其他卷.它能记 ...

  7. 解决zabbix的中文乱码

    CentOS7.1 x64上下载了zabbix官方的rpm包,导入后使用yum安装了zabbix 3.2.6,但是启动zabbix server的时候报了个段错误的错,谷歌了一会儿,发现段错误不止一次 ...

  8. Redis高可用详解:持久化技术及方案选择

    文章摘自:https://www.cnblogs.com/kismetv/p/9137897.html 前言 在上一篇文章中,介绍了Redis的内存模型,从这篇文章开始,将依次介绍Redis高可用相关 ...

  9. netty实现多个handler顺序调用

    在netty中,一次数据交互,可以由多个handler去处理,例如 handler1 和 handler2,那么,在前面那个handler的 messageReceived 的最后要加上 ctx.se ...

  10. 解决Android微信支付官方demo运行失败

    Android微信支付官方demo运行失败,在此简单记录一下解决步骤 1.httpclient错误 官方给的demo是eclipse的,打开之后提示httpclient的错误,我知道在as下解决htt ...