[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> ...
随机推荐
- Eclipse常用功能
功能(Functions):内置运行java程序的插件(JDT:java develop tools)工作集(WorkSet)(Task list)计划任务管理器(Mylyn)系统配置(Prefere ...
- 多线程 1-pthread 和NSThread
一.基本内容介绍: 进程: 正在运行的程序就叫进程 每个进程之间是相互独立的,每个进程均运行在其专用且受保护的内存空间内. 线程: 在程序内工作的基本执行单元(每个进程至 ...
- 部署图 Deployment Diagram
UML部署图描述了一个运行时的硬件结点,以及在这些结点上运行的软件组件的静态视图. 部署图显示了系统的硬件,安装在硬件上的软件,以及用于连接异构的机器之间的中间件. 下面这张图介绍了部署图的基本内容: ...
- SharePoint 优化显示WebParts
在开发sharepoint中,经常遇到需要自定义显示列表中的一部分作为导航的内容, 如公告栏,新闻链接,最新动态等.... 我们通常需要显示一个列表的标题,并且限制字符长度, 外加一些条件,如按创建的 ...
- 那些我用过的Android开源项目
1.RefreshActionItem 基于ActionBarSherlock库的一个扩展,在标题栏右边显示多种刷新效果的UI按钮. 项目主页: https://github.com/ManuelPe ...
- Netsharp快速入门(之12) 销售管理(开发发货单工作区)
作者:秋时 杨昶 时间:2014-02-15 转载须说明出处 4.4 发货单 4.4.1 部件工作区设置 1.设置部件工作区,需要设置的部件如下 2.设置单据和明细列表的字段,设置完成 ...
- 原型prototype -- 深入理解javascript
/* 原型Prototype */ //一.原型 //原型使用一 var calculator = function (dlg, tax) { this.dlg = dlg; this.tax = t ...
- 在云服务器搭建WordPress博客(四)WordPress的基本设置
前面说了 如何安装WordPress,接下来我们需要快速熟悉WordPress,以及进行一些必要的基本设置. 开始设置之前,建议大家先点击一篇左边菜单栏的每一个选项,看看到底是做什么用的.下面开始说一 ...
- svn: E155004: ..(path of resouce).. is already locked
svn: E155004: ..(path of resouce).. is already locked I'm getting an error when trying to commit a c ...
- JS中关于JS文件的引用以及问题
问题描述: 由于JSP中JS函数比较多,因此打算新建一个JS文件在JSP中引用JS文件,现在出现如下问题,JS如何引用时正确的,JS引用之后出现乱码如何解决? 问题解决: (1)JS ...