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的一些模板,发 ...
随机推荐
- c++(线性结构的处理)
我们知道,在内存中的空间都是连续的.也就是说,0x00000001下面的地址必然是0x00000002.所以,空间上是不会出现地址的突变的.那什么数据结构类型是连续内部空间呢,其实就是数组,当然也可以 ...
- 使用Redis和jackson操作json中遇到的坑
前言(可以略过) 最近在开发一个智能电表的管理系统,与常规的面向业务的系统不同.智能电表特点是每30分钟会向服务器发一次请求,报道自己目前的电表情况.然后服务器根据电表情况统计此电表的电量使用情况,包 ...
- 动态链接库(DLL)编写经验
我首先说明DLL的生成方法,之后再补充一些特殊之处. 生成方法: 1.对需要导出的类,在头文件中添加 #ifdef CLASS _API #define CLASS_API _declspec(dll ...
- [国嵌攻略][060][LCD工作原理解析]
LCD硬件体系 1.LCD液晶屏 液晶属于一种有机化合物,分子形状为长棒状,在不同的电流作用下,分子会有规律旋转,这样对光线产生一定的控制形成一个像素,而很多像素右可以构成完整的图像. LCD是Liq ...
- html button 点击链接
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 小白的Python之路 day5 configparser模块的特点和用法
configparser模块的特点和用法 一.概述 主要用于生成和修改常见配置文件,当前模块的名称在 python 3.x 版本中变更为 configparser.在python2.x版本中为Conf ...
- 访问网站出现 Directory Listing Denied This Virtual Directory
出现这个提示是指没有在您指定的目录找到默认首页,比如您直接输入域名访问空间, 但是出现以上提示,那么请检查目录下是否有 index.htm,index.html,index.asp,default.a ...
- js解析jsonArray嵌套
{ "data": { "BTC": [ 14781.51, 14888.9, 14900.04, 15098.88, 15308, 14880.01, 149 ...
- eclipse导入项目之后报错
一.项目本身就有错 二.jdk版本的问题 参考网址:http://jingyan.baidu.com/article/95c9d20da3ec5fec4e756186.html 从别的地方导入一个项目 ...
- 修改ncnn的openmp异步处理方法 附C++样例代码
ncnn刚发布不久,博主在ios下尝试编译. 遇上了openmp的编译问题. 寻找各种解决方案无果,亲自操刀. 采用std::thread 替换 openmp. ncnn项目地址: https://g ...