TOYS

http://poj.org/problem?id=2318

Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 19301   Accepted: 9106

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.
 
基础几何题,懒得写二分,直接暴力过了= =
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std; struct Point{
double x,y;
}; struct Line{
Point a,b;
}line[]; double Cross(Point A,Point B,Point C){
return (B.x-A.x)*(C.y-A.y)-(B.y-A.y)*(C.x-A.x);
} int ans[]; int main(){
int n,m;
double x1,y1,x2,y2,x,y;
int co=;
while(cin>>n){
if(!n) break;
memset(ans,,sizeof(ans));
cin>>m>>x1>>y1>>x2>>y2;
Point a,b;
if(co) cout<<endl;
for(int i=;i<n;i++){
cin>>x>>y;
a.x=x,a.y=y1;
b.x=y,b.y=y2;
line[i].a=a,line[i].b=b;
}
int j;
for(int i=;i<m;i++){
cin>>x>>y;
a.x=x,a.y=y;
for(j=;j<n;j++){
if(Cross(line[j].b,line[j].a,a)>){
break;
}
}
ans[j]++;
}
for(int i=;i<=n;i++){
cout<<i<<": "<<ans[i]<<endl;
}
co++;
}
}

TOYS(叉积)的更多相关文章

  1. POJ2318 TOYS[叉积 二分]

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

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

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

  3. 【POJ 2318】TOYS 叉积

    用叉积判断左右 快速读入写错了卡了3小时hhh #include<cmath> #include<cstdio> #include<cstring> #includ ...

  4. POJ 2318 TOYS 叉积

    题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...

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

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

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

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

  7. POJ2318:TOYS(叉积判断点和线段的关系+二分)&&POJ2398Toy Storage

    题目:http://poj.org/problem?id=2318 题意: 给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数.(其中这些线段 ...

  8. POJ-2318 TOYS,暴力+叉积判断!

                                                                 TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...

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

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

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

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

随机推荐

  1. Java-Runoob-高级教程-实例-数组:07. Java 实例 – 数组合并

    ylbtech-Java-Runoob-高级教程-实例-数组:07. Java 实例 – 数组合并 1.返回顶部 1. Java 实例 - 数组合并  Java 实例 以下实例演示了如何通过 List ...

  2. 9-16Jenkins-2定时任务

    定时任务 选择定时任务,点击 "?" 会弹出使用教程,但讨厌英语的人,自然选择现成的中文. 猪脚踏浪https://www.cnblogs.com/zsg88/p/9178625. ...

  3. java study2

    Intellj小技巧 数组 1.java数组元素类型是唯一的,即一个数组只能存储一种数据类型的数据,而不能存储多种数据类型的数据. 2.java数组的长度,一旦初始化完成,控件就被固定,即数组的长度将 ...

  4. dom2级事件兼容性写法

    添加事件 function addEvent(node,type,hander){ if(!node) return false;     //如果没有这个元素 ,直接返回: if(node.addE ...

  5. html5 如何实现客户端验证上传文件的大小

    在HTML 5中,现在可以在客户端进行文件上传时的校验了,比如用户选择文件后,可以 马上校验文件的大小和属性等.本文章向码农介绍html5 如何实现客户端验证上传文件的大小,感兴趣的码农可以参考一下. ...

  6. pip安装包(python安装gevent(win))

    下载: https://www.lfd.uci.edu/~gohlke/pythonlibs/#greenlet greenlet greenlet-0.4.14-cp36-cp36m-win_amd ...

  7. Python3 open()函数参数

    open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=No ...

  8. GET和POST的真正区别

    文章来源: http://www.nowamagic.net/librarys/veda/detail/1919 如果有人问你,GET和POST,有什么区别?你会如何回答? 我的经历 前几天有人问我这 ...

  9. JS数组对象的方法

    concat 返回一个新数组,这个数组是由两个或更多数组组合而成的 array.concat(b,c); join 返回字符串值,其中包括了连接到一起的数组的所有元素,元素由指定分隔符分割开来 arr ...

  10. Redis 配置节

    Redis 后面的配置基于4.0.9版本=>>>不指定版本信息的配置说明都是耍流氓 比如在4.0.9中没有vm相关的及glueoutputbuf的配置信息 部分常用配置节(后面有详细 ...