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

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.

题意:一些直线把一个矩形分成n+1份,给你m个点问每个点在哪一份里

用叉积判断左右关系,二分即可
//
// main.cpp
// poj2318
//
// Created by Candy on 2017/1/26.
// Copyright © 2017年 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
const int N=;
const double eps=1e-;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
inline int sgn(double x){
if(abs(x)<eps) return ;
else return x<?-:;
}
struct Vector{
double x,y;
Vector(double a=,double b=):x(a),y(b){}
bool operator <(const Vector &a)const{
return x<a.x||(x==a.x&&y<a.y);
}
};
typedef Vector Point;
Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);}
Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);}
Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);}
Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);}
bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==&&sgn(a.y-b.y)==;} double Cross(Vector a,Vector b){
return a.x*b.y-a.y*b.x;
} struct Line{
Point p;
Vector v;
Line(){}
Line(Point p,Vector v):p(p),v(v){}
bool operator <(const Line a)const{
return sgn(Cross(v,a.v))>=;
}
}a[N];
bool OnLeft(Line l,Point p){
return sgn(Cross(l.v,p-l.p))>=;
} int n,m,x,y,x2,y2,u,l,xx,yy;
int ans[N];
int main(int argc, const char * argv[]) {
while(true){
memset(ans,,sizeof(ans));
n=read();if(n==) break;
m=read();x=read();y=read();x2=read();y2=read();
for(int i=;i<=n;i++) u=read(),l=read(),a[i]=Line(Point(l,y2),Vector(u-l,y-y2));
a[++n]=Line(Point(x2,y2),Vector(,y-y2));
for(int i=;i<=m;i++){
x=read();y=read();
Point p=Point(x,y);
int l=,r=n,pos=-;
while(l<=r){
int mid=(l+r)>>;
if(OnLeft(a[mid],p)) pos=mid,r=mid-;
else l=mid+;
}
ans[pos]++;
}
for(int i=;i<=n;i++) printf("%d: %d\n",i-,ans[i]);
puts("");
} return ;
}
 

POJ2318 TOYS[叉积 二分]的更多相关文章

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

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

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

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

  3. POJ 2398 Toy Storage(叉积+二分)

    Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...

  4. poj 2318 叉积+二分

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 13262   Accepted: 6412 Description ...

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

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

  6. poj2318(叉积判断点在直线左右+二分)

    题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...

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

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

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

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

  9. POJ 2318 TOYS(点与直线的关系 叉积&&二分)

    题目链接 题意: 给定一个矩形,n个线段将矩形分成n+1个区间,m个点,问这些点的分布. 题解: 思路就是叉积加二分,利用叉积判断点与直线的距离,二分搜索区间. 代码: 最近整理了STL的一些模板,发 ...

随机推荐

  1. python笔记一(正则表达式)

    #!/usr/bin/env python # -*- coding: utf-8 -*- # 1 如果直接给出字符,则表示精确匹配 # 2 \d 表示数字, \w 表示字母或数字, . 可以匹配任意 ...

  2. iOS项目——项目开发环境搭建

    在开发项目之前,我们需要做一些准备工作,了解iOS扩展--Objective-C开发编程规范是进行开发的必备基础,学习iOS学习--Xcode9上传项目到GitHub是我们进行版本控制和代码管理的选择 ...

  3. c# base 和this 继承

    父类的构造函数总是在子类之前执行的.既先初始化静态构造函数,后初始化子类构造函数. public class BaseCircle { public BaseCircle() { Console.Wr ...

  4. python云算法

    http://www.runoob.com/python3/python3-basic-operators.html 本章节主要说明Python的运算符.举个简单的例子 4 +5 = 9 . 例子中, ...

  5. 记录linux tty的一次软锁排查

    本过程参照了某大侠的https://github.com/w-simon/debug/blob/master/tty_lock_cause_sytemd_hung , 当第二次出现的时候,还是排查了一 ...

  6. JVM-触发Full GC的情况

    除直接调用System.gc外,触发Full GC执行的情况有如下四种: 1.老年代空间不足 老年代空间只有在新生代对象转入及创建为大对象.大数组时才会出现不足现象,当执行Full GC后空间仍然不足 ...

  7. Linux网络设备驱动架构

    Linux网络设备驱动程序体系结构分为四层:网络协议接口层.网络设备接口层.提供实际功能的设备驱动层以及网络设备与媒介层. (1)网络协议接口层向网络层协议提供统一的数据包收发接口,不论上层协议是AR ...

  8. TypeError: 'encoding' is an invalid keyword argument for this function

    python 2.7 问题 data_file = open("F:\\MyPro\\data.yaml", "r", encoding='utf-8') 运行 ...

  9. scrapy_全站爬取

    如何查询scrapy有哪些模版? scrapy genspider –list 如何创建crawl模版? scrapy genspider -t crawl 域名 scrapy genspider - ...

  10. 四、Html常用标签

    1,列表相关标签 <ul>:定义无序列表,只能包含<li>子元素 <ol>:定义有序列表,只能包含<li>子元素,因为这个标签是有序的,所有这个标签还有 ...