用叉积判断左右

快速读入写错了卡了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. 如何用ZBrush做人体造型雕刻

    之前我们用ZBrush®中的Curves和Insert笔刷快速创建模型的躯干.四肢以及手指.经过老师耐心的讲解我们也收获了很多,知道了创建模型的流程和雕刻技巧.今天的ZBrush教程将结合一些新的雕刻 ...

  2. [转载]ExtJs4 笔记(12) Ext.toolbar.Toolbar 工具栏、Ext.toolbar.Paging 分页栏、Ext.ux.statusbar.StatusBar 状态栏

    作者:李盼(Lipan)出处:[Lipan] (http://www.cnblogs.com/lipan/)版权声明:本文的版权归作者与博客园共有.转载时须注明本文的详细链接,否则作者将保留追究其法律 ...

  3. Integer & int & == & equals

    int 是基本类型,直接存数值,integer是对象,用一个引用指向这个对象 int 是基本数据类型,Integer是类 int类的变量初始为0,Integer的变量则初始化为null. 如果只是用来 ...

  4. VS使用Sublime Text 主题

    VS主题需求 VS默认有三种主题Dark,Light,Blue,但你是否想寻找其它的主题呢?本文介绍两种方法来满足你的不同需求 1.微软官方扩展 微软官方推出的 Visaul Studio Color ...

  5. java 22 - 15 死锁的问题

    同步的弊端:  A:效率低  B:容易产生死锁 死锁:  两个或两个以上的线程在争夺资源的过程中,发生的一种相互等待的现象. 举例: 中国人,美国人一起吃饭. 正常情况: 中国人:筷子两支  美国人: ...

  6. 转: rapidJSON与jsoncpp语法说明

    转:  http://www.voidcn.com/blog/hudejun007/article/p-1811986.html

  7. 转:GCC,LLVM,Clang编译器对比

    GCC,LLVM,Clang编译器对比   转自: http://www.cnblogs.com/qoakzmxncb/archive/2013/04/18/3029105.html 在XCode中, ...

  8. Delphi常用系统函数总结

    Delphi常用系统函数总结 字符串处理函数 Unit System 函数原型 function Concat(s1 [, s2,..., sn]: string): string; 说明 与 S : ...

  9. Notes: Principles of fMRI 1 (Coursera)

    course link: https://class.coursera.org/fmri1-001 Part 1  ❤ Three fundmental goals in fMRI: localiza ...

  10. How To Create an IE-Only Stylesheet

    https://css-tricks.com/how-to-create-an-ie-only-stylesheet/ https://css-tricks.com/snippets/css/css- ...