【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 ...
随机推荐
- 【温故而知新-Javascript】使用 Ajax
Ajax 是现代Web 应用程序开发的一项关键工具.它让你能向服务器异步发送和接收数据,然后用 Javascript 解析. Ajax 是 Asynchronous JavaScript and XM ...
- Unity3D中的预制件(Prefab)的创建和使用说明!!!
首先我说明一下什么预制件? 在U3D里面我们叫它Prefab:我们可以这样理解:当制作好了游戏组件(场景中的任意一个gameobject),我们希望将它制作成一个组件模版,用于批量的套用工作,例如说场 ...
- 理解android.intent.action.MAIN 与 android.intent.category.LAUNCHER
刚才看了一下sundy的视频<LLY110426_Android应用程序启动>,里面讲到luncher这个activity通过获取应用程序信息来加载应用程序,显示给用户,其中就是通过一个应 ...
- bytes和bytearray
bytes bytes是Python 3中特有的,Python 2 里不区分bytes和str. Python 2中 >>> type(b'xxxxx') <type 'str ...
- XAMPP中proftpd的简明配置方法
XAMPP中proftpd的简明配置方法 用LAMPP的安装方法可以开一个默认的nobody用户,用lampp security就可以初始设置相应的默认用户密码.如果要有多用户,又怎样管理.目录怎 ...
- two sample ttest & paired ttst
来源:http://www.pinzhi.org/thread-1023-1-1.html 成对t检验Paired Test是对来自同一总体的样本,在不同条件影响下获取的2组样本进行分析,以评价不同条 ...
- There is no ‘Animation’ attached to the “Player” game object
There is no ‘Animation’ attached to the “Player” game object 在照着龚老师的Unity3D投篮游戏视频教程练习时,遇到这个错误提示. 我知道 ...
- maven spring profile 协同
请在网上查相关的使用情景,这里直接上要点.另外,可能不只一种方法,但这里只有一种. 1.POM.XML片段,使web.xml文件中有关活跃spring profile的内容可以被maven自动替换 & ...
- js 随笔
setInterval:即使在方法中使用了stopInterval这个方法也要执行完才会停止自行重复执行,解决:使用return false来跳出方法. JS string和num:当一个是字符串数字 ...
- Effective java 第2版 - 笔记(01) 单例(Singleton)的枚举(enum)实现
直接上代码: public enum Boss { INSTANCE; private String name; public void doSomeThing() { System.out.prin ...