【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 ...
随机推荐
- Java—Servlet开发
Servlet API中有4个java包: javax.servlet:包含定义Servlet与Servlet容器之间契约的类与接口. javax.servlet.http:包含定义HTTPServl ...
- 使用gulp将移动端px转为rem
使用gulp的插件可以很方便的将xp转为rem,在布局的时候使用@1x .@2x布局,即10rem=device-width:@1x即设计图为320px,1rem对应的10px像素,相对的@2x即为布 ...
- jquery工具方法proxy
proxy : 改变this指向 使用方法1:function show(){ alert(this); }$.proxy(show,document)(); //document 使用方法2:fu ...
- JS中NULL和Undefined的区别
NULL是表示一个”无“的对象,转换成数值为0:undefined是一个“无”的原始值,转为数值为NaN: 当声明的变量还未被初始化时,变量的默认值为undefined: null用来表示尚未存在的对 ...
- javascript中String的fromCharCode()方法
前几天遇到一个bug,后端的模板引擎在输出形如: <div title="111 aaa">内容</div> 这样的内容时,无法输出' '空格,所以只能用' ...
- 转 mvc项目中,解决引用jquery文件后智能提示失效的办法
mvc项目中,解决用Url.Content方法引用jquery文件后智能提示失效的办法 这个标题不知道要怎么写才好, 但是希望文章的内容对大家有帮助. 场景如下: 我们在用开发开发程序的时候,经常 ...
- C# 断点续传原理与实现
在了解HTTP断点续传的原理之前,让我们先来了解一下HTTP协议,HTTP协议是一种基于tcp的简单协议,分为请求和回复两种.请求协议是由 客户机(浏览器)向服务器(WEB SERVER)提交请求时发 ...
- Python自动补全
转自:http://blog.linuxeye.com/324.html Python自动补全有vim编辑下和python交互模式下,下面分别介绍如何在这2种情况下实现Tab键自动补全. 一.vim ...
- React Native 项目运行在 Web 浏览器上面
React Native 的出现,让前端工程师拥有了使用 JavaScript 编写原生 APP 的能力.相比之前的 Web app 来说,对于性能和用户体验提升了非常多. 但是 React Nati ...
- ESXi 5.5 命令行克隆虚拟机
1. 开启ESXi的SSH功能,用vSphere Client登录ESXi, 选中服务器, 在右侧标签栏选择Configuration->SecurityProfile->Services ...