【POJ 2318】TOYS 叉积
用叉积判断左右
快速读入写错了卡了3小时hhh
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define N 5003
#define read(x) x = getint()
using namespace std;
inline int getint() {
int fh = 1, k = 0; char c = getchar();
for(; c < '0' || c > '9'; c = getchar())
if (c == '-') fh = -1;
for(; c >= '0' && c <= '9'; c = getchar())
k = k * 10 + c - '0';
return k * fh;
} struct Point {
int x, y;
Point(int _x = 0, int _y = 0) : x(_x), y(_y) {}
};
Point operator - (Point a, Point b) {
return Point(a.x - b.x, a.y - b.y);
}
bool Cross(Point a, Point b) {
return a.x * b.y - a.y * b.x > 0;
} struct node {
Point a, b;
}; Point toy;
node line[N];
int ans[N], n, m, up, left, down, right; int main() {
read(n);
while (n) {
read(m); read(left); read(up); read(right); read(down);
for(int i = 1; i <= n; ++i) {
scanf("%d%d", &line[i].a.x, &line[i].b.x);
line[i].a.y = up;
line[i].b.y = down;
} for(int i = 0; i <= n; ++i)
ans[i] = 0; while (m--) {
read(toy.x); read(toy.y);
int l = 1, r = n-1, mid, zuo, you; zuo = Cross(line[1].a - line[1].b, toy - line[1].b);
you = Cross(line[n].a - line[n].b, toy - line[n].b);
if (zuo) {
++ans[0];
continue;
}
if (!you) {
++ans[n];
continue;
} while (l <= r) {
mid = (l + r) >> 1;
zuo = Cross(line[mid].a - line[mid].b, toy - line[mid].b);
you = Cross(line[mid + 1].a - line[mid + 1].b, toy - line[mid + 1].b);
if (zuo)
r = mid - 1;
else if (!you)
l = mid + 1;
else
break;
}
++ans[mid];
} for(int i = 0; i <= n; ++i)
printf("%d: %d\n", i, ans[i]);
puts("");
read(n);
} return 0;
}
无语······
【POJ 2318】TOYS 叉积的更多相关文章
- POJ 2318 TOYS (叉积+二分)
题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...
- POJ 2318 TOYS 叉积
题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...
- POJ 2318 TOYS(叉积+二分)
题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...
- poj 2318 TOYS (二分+叉积)
http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 101 ...
- 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage
POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...
- poj 2318 TOYS & poj 2398 Toy Storage (叉积)
链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...
- 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage
题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...
- POJ 2318 TOYS && POJ 2398 Toy Storage(几何)
2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...
- POJ 2318/2398 叉积性质
2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...
- POJ 2318 TOYS (计算几何,叉积判断)
TOYS Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8661 Accepted: 4114 Description ...
随机推荐
- HTML标签----图文详解
国庆节快乐,还在加班的童鞋,良辰必有重谢! 本文主要内容 头标签 排版标签:<p> <br> <hr> <center> ...
- Spring AOP 5种通知与java动态代理
接口,要求为每个方法前后添加日志 @Component("arithmeticCalculator") public class ArithmeticCalculatorImpl ...
- Editor扩展之查看Prefab用在那儿
Prefab查找需求 在项目开发阶段的中后期,工程中有越来越多的Prefab,当我们要修改一个prefab或删除无用的prefab时,或许我们不是那么清楚该prefab在那些场景中使用着或从未使用过, ...
- 怎样使用VMware Workstation(虚拟机)
怎样使用VMware Workstation(虚拟机) 听语音 浏览:66981 | 更新:2010-12-06 16:26 | 标签:vmware 1 2 3 4 5 6 7 分步阅读 一键约师傅 ...
- HTML 学习笔记 CSS(选择器)
CSS元素选择器 最常见的CSS 选择器就是元素选择器 换句话说 文档的元素就是最基本的选择器 如果设置HTML样式 选择器通常就是某个HTML元素 比如p h1 em a 甚至可以是HTML本身 h ...
- nginx访问白名单设置以及根据$remote_addr分发
在日常运维工作中,会碰到这样的需求:设置nginx的某个域名访问只对某些ip开放,其他ip的客户端都不能访问.达到这样的目的一般有下面两种设置方法:(1)针对nginx域名配置所启用的端口(一般是80 ...
- Python的高级特性12:类的继承
在面向对象的程序设计中,继承(Inheritance)允许子类从父类那里获得属性和方法,同时子类可以添加或者重载其父类中的任何方法.在C++和Java的对象模型中,子类的构造函数会自动调用父类的构造函 ...
- sql语句获取今天、昨天、近7天、本周、上周、本月、上月、半年数据
话说有一文章表article,存储文章的添加文章的时间是add_time字段,该字段为int()类型的,现需要查询今天添加的文章总数并且按照时间从大到小排序,则查询语句如下: select * fro ...
- BZOJ 1251: 序列终结者
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MB Submit: 3773 Solved: 1579 [Submit][Status][Dis ...
- linux查看出口ip 及w3m字符浏览器
Linux 查看服务器出口IP 字符浏览器: http://wiki.ubuntu.org.cn/W3m