用叉积判断左右

快速读入写错了卡了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 叉积的更多相关文章

  1. POJ 2318 TOYS (叉积+二分)

    题目: Description Calculate the number of toys that land in each bin of a partitioned toy box. Mom and ...

  2. POJ 2318 TOYS 叉积

    题目大意:给出一个长方形盒子的左上点,右下点坐标.给出n个隔板的坐标,和m个玩具的坐标,求每个区间内有多少个玩具. 题目思路:利用叉积判断玩具在隔板的左方或右方,并用二分优化查找过程. #includ ...

  3. POJ 2318 TOYS(叉积+二分)

    题目传送门:POJ 2318 TOYS Description Calculate the number of toys that land in each bin of a partitioned ...

  4. poj 2318 TOYS (二分+叉积)

    http://poj.org/problem?id=2318 TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 101 ...

  5. 向量的叉积 POJ 2318 TOYS & POJ 2398 Toy Storage

    POJ 2318: 题目大意:给定一个盒子的左上角和右下角坐标,然后给n条线,可以将盒子分成n+1个部分,再给m个点,问每个区域内有多少各点 这个题用到关键的一步就是向量的叉积,假设一个点m在 由ab ...

  6. poj 2318 TOYS &amp; poj 2398 Toy Storage (叉积)

    链接:poj 2318 题意:有一个矩形盒子,盒子里有一些木块线段.而且这些线段坐标是依照顺序给出的. 有n条线段,把盒子分层了n+1个区域,然后有m个玩具.这m个玩具的坐标是已知的,问最后每一个区域 ...

  7. 简单几何(点与线段的位置) POJ 2318 TOYS && POJ 2398 Toy Storage

    题目传送门 题意:POJ 2318 有一个长方形,用线段划分若干区域,给若干个点,问每个区域点的分布情况 分析:点和线段的位置判断可以用叉积判断.给的线段是排好序的,但是点是无序的,所以可以用二分优化 ...

  8. POJ 2318 TOYS && POJ 2398 Toy Storage(几何)

    2318 TOYS 2398 Toy Storage 题意 : 给你n块板的坐标,m个玩具的具体坐标,2318中板是有序的,而2398无序需要自己排序,2318要求输出的是每个区间内的玩具数,而231 ...

  9. POJ 2318/2398 叉积性质

    2318 2398 题意:给出n条线将一块区域分成n+1块空间,再给出m个点,询问这些点在哪个空间里. 思路:由于只要求相对位置关系,而对具体位置不关心,那么易使用叉积性质得到相对位置关系(左侧/右侧 ...

  10. POJ 2318 TOYS (计算几何,叉积判断)

    TOYS Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8661   Accepted: 4114 Description ...

随机推荐

  1. 边工作边刷题:70天一遍leetcode: day 1

    (今日完成:Two Sum, Add Two Numbers, Longest Substring Without Repeating Characters, Median of Two Sorted ...

  2. AngularJS Filters

    过滤器可以使用一个管道字符(|)添加到表达式和指令中. AngularJS 过滤器 AngularJS 过滤器可用于转换数据: 过滤器 描述 currency 格式化数字为货币格式. filter 从 ...

  3. AC日记——最长最短单词 openjudge 1.7 25

    25:最长最短单词 总时间限制:  1000ms 内存限制:  65536kB 描述 输入1行句子(不多于200个单词,每个单词长度不超过100),只包含字母.空格和逗号.单词由至少一个连续的字母构成 ...

  4. Markdown(MD)写作

    简洁的写作 目前正逐步使用Makedown来写博客或其它的文档,本文记录一下Markdown的相关知识 Markdown语法 标题 # 内容 (一级标题) ## 内容 (二级标题) ### 内容 (三 ...

  5. HQL基础查询语句

    HQL基础查询语句 1.使用hql语句检索出Student表中的所有列 //核心代码 @Test public void oneTest() { Query query=session.createQ ...

  6. Ajax讲解

    AJAX:即"Asynchronous Javascript And XML"(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术. AJAX = 异步 ...

  7. java 22 - 5 多线程之获取和设置线程对象的名称

    如何获取线程对象的名称呢? public final String getName():获取线程的名称.如何设置线程对象的名称呢? public final void setName(String n ...

  8. code blocks 如何实现一键代码格式化

    问题:code blocks 如何实现一键代码格式化 解答:直接右键,选择format use ASstyle

  9. UIButton(改变Title和image位置)

    UIButton *btn = [[UIButton alloc] init]; [btn setFrame:frame]; [btn setTitleColor:titleColor forStat ...

  10. LInux下修改 ~/.bashrc 文件source ~/.bashrc 后 shell 命令 失效 任何命令都显示 “ bash XX :未找到命令”

    原因:在java安装后进行环境变量配置其中 export JAVA_HOME="/opt/java/jdk1.8" export PATH=$JAVA_HOME 即结束 错误原因: ...