来源 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. VTK计算网格模型上的最短路径

    Dijkstra algorithm to compute the graph geodesic.Takes as input a polygonal mesh and performs a sing ...

  2. 【ShoppingPeeker】-基于Webkit内核的爬虫蜘蛛引擎 ShoppingWebCrawler的姊妹篇-可视化任务Web管理

    ShoppingPeeker 这个项目是蜘蛛项目的可视化任务站点. 项目github地址:ShoppingPeeker 开发语言:C# 开发工具:Visual Studio 2017 +.Net Co ...

  3. Axure RP for Mac(网站交互式原型设计工具)破解版安装

    1.软件简介    Axure RP 是 macOS 系统上一款最知名和最强大的原型设计工具,增加了大量新的特性,如应用多个动画,并同一时间运行一个小部件,如褪色,同时移动等,而且具有全新的图标和界面 ...

  4. FragmentPagerAdapter 与 FragmentStatePagerAdapter 的区别

    参考链接: http://blog.csdn.net/dreamzml/article/details/9951577 简单来说前者适合静态.少量的Fragment 后者适合动态.较多的Fragmen ...

  5. 【Linux高级驱动】I2C驱动框架分析

    1.i2c-dev.c(i2c设备驱动组件层) 功能:1)给用户提供接口 i2c_dev_init  //入口函数 /*申请主设备号*/ register_chrdev(I2C_MAJOR(), &q ...

  6. MySQL中文参考手册

    1 MySQL 的一般信息 这是MySQL参考手册:它记载了MySQL版本3.23.7-alpha. MySQL 是一个快速.多线程.多用户和强壮的SQL数据库服务器. 对Unix和 OS/2 平台, ...

  7. 推荐几个Windows工具软件: Stickies - 桌面贴

    主页: http://www.zhornsoftware.co.uk/stickies/index.html Stickies work like Post-it notes for your PC. ...

  8. cordova打包vue2(webpack)android、ios app

    使用cordova打包vue2(webpack)app for android ios1.vue项目通过vue-cli脚手架建立项目,使用webpack进行打包,下边是一整套命令. #npm 版本最好 ...

  9. Java编程的逻辑 (81) - 并发同步协作工具

    ​本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http: ...

  10. Java知多少(104)网络编程之统一资源定位符URL

    统一资源定位符URL(Uniform Resource Locator)是www客户机访问Internet时用来标识资源的名字和地址.超文本链路由统一资源定位符URL维持.URL的格式是: <M ...