[POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)
题目链接:http://poj.org/problem?id=2398
思路RT,和POJ2318一样,就是需要排序,输出也不一样。手工画一下就明白了。注意叉乘的时候a×b是判断a在b的顺时针还是逆时针侧,>0是顺时针测,<0是逆时针侧,本题对应看成右、左侧,特别注意。
/*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; typedef struct Point {
int x, y;
Point() {}
Point(int xx, int yy) : x(xx), y(yy) {}
bool operator==(Point p) {
return x == p.x && y == p.y;
}
bool operator<(Point p) {
if(x == p.x) return y < p.y;
return x < p.x;
}
}Point;
typedef struct Line {
Point a, b;
Line() {}
Line(Point aa, Point bb) : a(aa), b(bb) {}
}Line;
const int maxn = ;
const int maxm = ;
Line line[maxn];
Point s, e;
int n, m;
int tmp[maxm];
int ans[maxm]; int ok(Point p, Line l) {
RT ((l.b.y-l.a.y)*(p.x-l.a.x)-(p.y-l.a.y)*(l.b.x-l.a.x));
} bool cmp(Line a, Line b) {
if(a.a == b.a) return a.b < b.b;
return a.a < b.a;
} int main() {
// FRead();
int x1, x2;
bool flag = ;
while(~Rint(n) && n) {
Cls(tmp); Cls(ans);
Rint(m); Rint(s.x); Rint(s.y); Rint(e.x); Rint(e.y);
Rep(i, n) {
Rint(x1); Rint(x2);
line[i] = Line(Point(x1, s.y), Point(x2, e.y));
}
line[n] = Line(Point(e.x, s.y), e);
Point p;
sort(line, line+n+, cmp);
W(m) {
Rint(p.x); Rint(p.y);
int l = , r = n;
int ret;
while(l <= r) {
int m = (l + r) >> ;
if(ok(p, line[m]) > ) {
ret = m;
r = m - ;
}
else l = m + ;
}
tmp[ret]++;
}
int hi = ;
Rep(i, n+) {
hi = max(hi, tmp[i]);
ans[tmp[i]]++;
}
printf("Box\n");
For(i, , hi+) {
if(ans[i]) printf("%d: %d\n", i, ans[i]);
}
}
RT ;
}
[POJ2398]Toy Storage(计算几何,二分,判断点在线段的哪一侧)的更多相关文章
- poj2398 Toy Storage 计算几何,叉积,二分
poj2398 Toy Storage 链接 poj 题目大意 这道题的大概意思是先输入6个数字:n,m,x1,y1,x2,y2.n代表卡片的数量,卡片竖直(或倾斜)放置在盒内,可把盒子分为n+1块区 ...
- 2018.07.04 POJ 2398 Toy Storage(二分+简单计算几何)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad have a problem: their ch ...
- POJ 2398 Toy Storage (叉积判断点和线段的关系)
题目链接 Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4104 Accepted: 2433 ...
- poj 2398 Toy Storage(计算几何)
题目传送门:poj 2398 Toy Storage 题目大意:一个长方形的箱子,里面有一些隔板,每一个隔板都可以纵切这个箱子.隔板将这个箱子分成了一些隔间.向其中扔一些玩具,每个玩具有一个坐标,求有 ...
- poj 2398 Toy Storage(计算几何 点线关系)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4588 Accepted: 2718 Descr ...
- poj 2398(叉积判断点在线段的哪一侧)
Toy Storage Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 5016 Accepted: 2978 Descr ...
- POJ 2398 Toy Storage(计算几何)
题意:给定一个如上的长方形箱子,中间有n条线段,将其分为n+1个区域,给定m个玩具的坐标,统计每个区域中的玩具个数. 题解:通过斜率判断一个点是否在两条线段之间. /** 通过斜率比较点是否在两线段之 ...
- poj 2398 Toy Storage【二分+叉积】
二分点所在区域,叉积判断左右 #include<iostream> #include<cstdio> #include<cstring> #include<a ...
- [poj2398]Toy Storage
接替关键:和上题类似,输出不同,注意输入这道题需要排序. #include<cstdio> #include<cstring> #include<algorithm> ...
随机推荐
- php配置步奏
web运行大致流程 浏览器输入地址,回车(发送请求) 根据规则找到对应web服务器.规则如下: 首先在本机hosts文件中找对应IP 如果hosts中没有找到,则到互联网上找对应IP 如果还 ...
- VBS基础篇 - 循环
经常地,当编写代码时,我们希望将一段代码执行若干次,我们可以在代码中使用循环语句来完成这项工作. 循环可分为三类:一类在条件变为 False 之前重复执行语句,一类在条件变为 True 之前重复执行语 ...
- OC的类的构造方法
构造方法:用来初始化对象的:首先分解一下创建对象的过程: Person *p = [Person new]; // new方法是alloc 和 init 这两个方法的组合: 完整的创建可用对象的过程: ...
- Careercup - Facebook面试题 - 6026101998485504
2014-05-02 10:47 题目链接 原题: Given an unordered array of positive integers, create an algorithm that ma ...
- Madwifi Mad coding:自底向上分析associated_sta的更新过程 —— RSSI和MACADDR等信息获取的底层原理
Madwifi驱动工作在AP模式下时,可以在/proc/net/madwifi/ath0/associated_sta文件中得到所有接入的用户的MAC地址.实时平均RSSI,和last_rx三个信息. ...
- python 安装 easy_intall 和 pip python无root权限安装
http://www.cnblogs.com/haython/p/3970426.html easy_install和pip都是用来下载安装Python一个公共资源库PyPI的相关资源包的 首先安装e ...
- HTML5网页制作教程:HTML5块级链接
网页制作Webjx文章简介:Web 标准中处处充满了打脸行为,这条规则现在已经失效了!在那篇文章发布一个月后,HTML5doctor 发表了 “Block-level” links in HTML5, ...
- Matlab计算两集合间的海明距离
一.问题描述 B1[1 2 3 4 5 6 7 8 9] B2[12 13 14 21 31 41 51 1 1 81 1 1] 两个十进制矩阵,行数不一样,分别是n1和n2,列数必须一致,为nwo ...
- jquery的一些用法
一.选择器 单选按钮:$(this).find(".answer").find("input[name='answer_" + id + "']:ch ...
- MongoDB { code: 18, ok: 0.0, errmsg: "auth fails" } 原因
MongoDB出现 { code: 18, ok: 0.0, errmsg: "auth fails" } 错误的原因: 1.账号密码错误 2.账号不属于该数据库