POJ2318 TOYS[叉积 二分]
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 14433 | Accepted: 6998 |
Description
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
Output
//
// 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[叉积 二分]的更多相关文章
- POJ2318 TOYS(叉积判断点与直线的关系+二分)
Calculate the number of toys that land in each bin of a partitioned toy box. Mom and dad have a prob ...
- POJ 2318 TOYS (叉积+二分)
题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...
- POJ 2398 Toy Storage(叉积+二分)
Description Mom and dad have a problem: their child, Reza, never puts his toys away when he is finis ...
- poj 2318 叉积+二分
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13262 Accepted: 6412 Description ...
- POJ-2318 TOYS,暴力+叉积判断!
TOYS 2页的提交记录终于搞明白了. 题意:一个盒子由n块挡板分成n+1块区 ...
- poj2318(叉积判断点在直线左右+二分)
题目链接:https://vjudge.net/problem/POJ-2318 题意:有n条线将矩形分成n+1块,m个点落在矩形内,求每一块点的个数. 思路: 最近开始肝计算几何,之前的几何题基本处 ...
- POJ 2318 TOYS(叉积+二分)
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...
- POJ 2318 TOYS【叉积+二分】
今天开始学习计算几何,百度了两篇文章,与君共勉! 计算几何入门题推荐 计算几何基础知识 题意:有一个盒子,被n块木板分成n+1个区域,每个木板从左到右出现,并且不交叉. 有m个玩具(可以看成点)放在这 ...
- POJ 2318 TOYS(点与直线的关系 叉积&&二分)
题目链接 题意: 给定一个矩形,n个线段将矩形分成n+1个区间,m个点,问这些点的分布. 题解: 思路就是叉积加二分,利用叉积判断点与直线的距离,二分搜索区间. 代码: 最近整理了STL的一些模板,发 ...
随机推荐
- POI实现大数据EXCLE导入导出,解决内存溢出问题
使用POI能够导出大数据保证内存不溢出的一个重要原因是SXSSFWorkbook生成的EXCEL为2007版本,修改EXCEL2007文件后缀为ZIP打开可以看到,每一个Sheet都是一个xml文件, ...
- 制作ssh互信的docker镜像
Dockerfile FROM ubuntu:16.04 # package RUN apt-get update; apt-get -y install ssh COPY ssh_config /e ...
- Ubuntu下 jdk环境变量设置
流程 1. 官网下载对应的jdk文件 2. 在根目录 / 下创建一个java目录 mkdir /java 3. 使用mv命令 将下载下来的文件(压缩格式),移动到上一步创建的/java目录下 Ps ...
- Spark算子--map和flatMap
map和flatMap--Transformation类算子 代码示例 result
- 通过Xshell如何从Linux服务器下载文件(亲测可行)
到网上下载lrzsz安装包,这里以lrzsz-0.12.20.tar.gz为例 2 打开终端 cd 到安装包所在目录 tar zxvf lrzsz-0.12.20.tar.gz 解压安装包 3 进入解 ...
- mysql 远程连接数据库的二种方法
一.连接远程数据库: 1.显示密码 如:MySQL 连接远程数据库(192.168.5.116),端口"3306",用户名为"root",密码"123 ...
- OpenCV3.0 HDR(高动态范围)示例代码以及用法
OpenCV 3.0以及以后版本集成了HDR算法,样例代码的路径为: .\sources\samples\cpp\tutorial_code\photo\hdr_imaging.cpp. 实现算法的参 ...
- jQuery 表单
1.一般输入信息的提示用<span> 属性为text 2.<input>只有设置了 name 属性的表单元素才能在提交表单时传递它们的值. 3.blur 失去焦点 4.$. ...
- 在Pycharm中运行Scrapy爬虫项目的基本操作
目标在Win7上建立一个Scrapy爬虫项目,以及对其进行基本操作.运行环境:电脑上已经安装了python(环境变量path已经设置好), 以及scrapy模块,IDE为Pycharm .操作如下: ...
- 开地址哈希表(Hash Table)的原理描述与冲突解决
在开地址哈希表中,元素存放在表本身中.这对于某些依赖固定大小表的应用来说非常有用.因为不像链式哈希表在每个槽位上有一个"桶"来存储冲突的元素,所以开地址哈希表需要通过另一种方法来解 ...