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的一些模板,发 ...
随机推荐
- js onclick传递 对象
在html onclick中如果参数直接传递一个参数js会报错. 如果想要onclick传递参数需要这么做: var user = {id:1, name:'hk'}; var ele = '< ...
- yum指令
接上个教程,如果用yum list 命名,运行后出现如下结果:则正确搭建了环境 如 yum search httpd 搜索apache的包 安装gcc ,是c语言的编译器 注意:LANG是临时改变的. ...
- 使用Android Studio过程中,停留在“Building ‘工程名’ Gradle project info”的解决方法
http://www.loverobots.cn/in-the-process-of-using-studio-android-the-solution-of-the-project-info-gra ...
- 织梦CMS提示DedeTag Engine Create File False错误的解决办法总结
今天帮客户升级站点,遇到了一个老问题,生成栏目的时候提示"DedeTag Engine Create File False",突然发觉这个问题竟然在以前做站的时候困扰过我多次,于是 ...
- syntax error, unexpected '['
在用ThinkPHP框架做了个小的应用 我在本地搭建的服务器,进行测试好着的. 但是放到别的地方后,出现以下报错 syntax error, unexpected '[' 错误位置是在我自己写的一个A ...
- nginx重启报找不到nginx.pid的解决方法
nginx被停止(nginx -s stop)或者直接杀掉了进程(kill -9 nginx的进程号)后,调用命令(nginx -s reload 或者 nginx -s reopen)会报错:无法找 ...
- php 抽奖概率 随机数
<?php $prize_arr = array( '0' => array('id' => 1, 'title' => 'iphone5s', 'v' => 5), ' ...
- Linux下环境变量设置的三种方法
如想将一个路径加入到$PATH中,可以像下面这样做: 1.控制台中设置,不赞成这种方式,因为他只对当前的shell 起作用,换一个shell设置就无效了:$PATH="$PATH" ...
- 2017-06-20 (pwd ls cd)
pwd pwd 显示当前所在的位置 pwd -P 如果是链接文件,显示链接文件所指的位置 ls ls 查询目录中的内容 ls -a 显示所有的文件,包含隐藏的文件 -l 显示详细的信息 ...
- CSS深入理解学习笔记之z-index
1.z-index基础 z-index含义:指定了元素及其子元素的"z顺序",而"z顺序"可以决定元素的覆盖顺序.z-index值越大越在上面. z-index ...