bzoj1007题解
【题意分析】
给你n个上半平面,求包含这些上半平面的交的上半平面。
【解题思路】
按斜率排序,用单调栈维护一个下凸壳即可。复杂度O(nlog2n)。
【参考代码】
#include <cctype>
#include <cmath>
#include <cstdio>
#define REP(I,start,end) for(int I=(start);I<=(end);I++)
#define PER(I,start,end) for(int I=(start);I>=(end);I--)
inline int space()
{
return putchar(' ');
}
inline int enter()
{
return putchar('\n');
}
inline bool eoln(char ptr)
{
return ptr=='\n';
}
inline bool eof(char ptr)
{
return ptr=='\0';
}
inline int getint()
{
char ch=getchar();
for(;!isdigit(ch)&&ch!='+'&&ch!='-';ch=getchar());
bool impositive=ch=='-';
if(impositive)
ch=getchar();
int result=;
for(;isdigit(ch);ch=getchar())
result=(result<<)+(result<<)+ch-'';
return impositive?-result:result;
}
template<typename integer> inline int write(integer n)
{
integer now=n;
bool impositive=now<;
if(impositive)
{
putchar('-');
now=-now;
}
char sav[];
sav[]=now%+'';
int result=;
for(;now/=;sav[result++]=now%+'');
PER(i,result-,)
putchar(sav[i]);
return result+impositive;
}
template<typename real> inline bool fequals(real one,real another,real eps=1e-)
{
return fabs(one-another)<eps;
}
template<typename real> inline bool funequals(real one,real another,real eps=1e-)
{
return fabs(one-another)>=eps;
}
template<typename T=double> struct Point
{
T x,y;
Point()
{
x=y=;
}
Point(T _x,T _y)
{
x=_x;
y=_y;
}
bool operator==(const Point<T> &another)const
{
return fequals(x,another.x)&&fequals(y,another.y);
}
bool operator!=(const Point<T> &another)const
{
return funequals(x,another.x)||funequals(y,another.y);
}
Point<T> operator+(const Point<T> &another)const
{
Point<T> result(x+another.x,y+another.y);
return result;
}
Point<T> operator-(const Point<T> &another)const
{
Point<T> result(x-another.x,y-another.y);
return result;
}
Point<T> operator*(const T &number)const
{
Point<T> result(x*number,y*number);
return result;
}
Point<double> operator/(const T &number)const
{
Point<double> result(double(x)/number,double(y)/number);
return result;
}
double theta()
{
return x>?(y<)**M_PI+atan(y/x):M_PI+atan(y/x);
}
double theta_x()
{
return !x?M_PI/:atan(y/x);
}
double theta_y()
{
return !y?M_PI/:atan(x/y);
}
};
template<typename T> inline T dot_product(Point<T> A,Point<T> B)
{
return A.x*B.x+A.y*B.y;
}
template<typename T> inline T cross_product(Point<T> A,Point<T> B)
{
return A.x*B.y+A.y*B.x;
}
template<typename T> inline T SqrDis(Point<T> a,Point<T> b)
{
return sqr(a.x-b.x)+sqr(a.y-b.y);
}
template<typename T> inline double Euclid_distance(Point<T> a,Point<T> b)
{
return sqrt(SqrDis(a,b));
}
template<typename T> inline T Manhattan_distance(Point<T> a,Point<T> b)
{
return fabs(a.x-b.x)+fabs(a.y-b.y);
}
template<typename T=double> struct kbLine
{
//line:y=kx+b
T k,b;
kbLine()
{
k=b=;
}
kbLine(T _k,T _b)
{
k=_k;
b=_b;
}
bool operator==(const kbLine<T> &another)const
{
return fequals(k,another.k)&&fequals(b,another.b);
}
bool operator!=(const kbLine<T> &another)const
{
return funequals(k,another.k)||funequals(b,another.b);
}
bool operator<(const kbLine<T> &another)const
{
return k<another.k;
}
bool operator>(const kbLine<T> &another)const
{
return k>another.k;
}
template<typename point_type> inline bool build_line(Point<point_type> A,Point<point_type> B)
{
if(fequals(A.x,B.x))
return false;
k=T(A.y-B.y)/(A.x-B.x);
b=A.y-k*A.x;
return true;
}
double theta_x()
{
return atan(k);
}
double theta_y()
{
return theta_x()-M_PI/;
}
};
template<typename T> bool parallel(kbLine<T> A,kbLine<T> B)
{
return A!=B&&(fequals(A.k,B.k)||A.k!=A.k&&B.k!=B.k);
}
template<typename T> Point<double> *cross(kbLine<T> A,kbLine<T> B)
{
if(A==B||parallel(A,B))
return NULL;
double _x=double(B.b-A.b)/(A.k-B.k);
Point<double> *result=new Point<double>(_x,A.k*_x+A.b);
return result;
}
//======================================Header Template=====================================
#include <algorithm>
using namespace std;
int stack[];
struct _line
{
kbLine<> _l;
int order;
bool operator<(const _line &T)const
{
return _l<T._l||parallel(_l,T._l)&&_l.b>T._l.b;
}
}lines[];
inline bool Order(int A,int B)
{
return lines[A].order<lines[B].order;
}
int main()
{
int n=getint();
REP(i,,n)
{
lines[i].order=i;
scanf("%lf%lf",&lines[i]._l.k,&lines[i]._l.b);
}
sort(lines+,lines+n+);
int top=stack[]=,i=;
while(i<=n)
{
for(;i<=n&&(lines[i]._l==lines[stack[top]]._l||parallel(lines[i]._l,lines[stack[top]]._l));i++);
for(;i<=n&&top>;top--)
{
Point<double> *last=cross(lines[stack[top-]]._l,lines[stack[top]]._l),*now=cross(lines[i]._l,lines[stack[top]]._l);
if(last->x<now->x)
break;
}
stack[++top]=i++;
}
sort(stack+,stack+top+,Order);
REP(i,,top)
{
write(lines[stack[i]].order);
space();
}
enter();
return ;
}
bzoj1007题解的更多相关文章
- 【BZOJ1007】水平可见直线(单调栈)
[BZOJ1007]水平可见直线(单调栈) 题解 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为 可见的 ...
- 【BZOJ1007】[HNOI2008]水平可见直线 半平面交
[BZOJ1007][HNOI2008]水平可见直线 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见 ...
- 2016 华南师大ACM校赛 SCNUCPC 非官方题解
我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...
- noip2016十连测题解
以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- BZOJ-2561-最小生成树 题解(最小割)
2561: 最小生成树(题解) Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1628 Solved: 786 传送门:http://www.lyd ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解
题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...
- 2016ACM青岛区域赛题解
A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- poj1399 hoj1037 Direct Visibility 题解 (宽搜)
http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...
随机推荐
- git 分支相关操作
git status 查看当前工作区 会显示分支 如下 D:\工程\vue_study\testplat_vue>git statusOn branch masternothing to co ...
- 面试之加分项vue(没看懂,。。。。)
对大部分人来说,掌握Vue.js基本的几个API后就已经能够正常地开发前端网站.但如果你想更加高效地使用Vue来开发,成为Vue.js大师,那下面我要传授的这五招你一定得认真学习一下了.在面试过程很多 ...
- 2、Python 基础类型 -- String 字符串类型
字符串常用的方法: 1.分割:string.split(str="", num=string.count(str)) 以 str 为分隔符切片 string,如果 num 有指 ...
- mysql 日期函数大全
对于每个类型拥有的值范围以及并且指定日期何时间值的有效格式的描述见7.3.6 日期和时间类型. 这里是一个使用日期函数的例子.下面的查询选择了所有记录,其date_col的值是在最后30天以内: my ...
- nc临时开启端口并监听
port="6379 3306 27017 4505 4506 24007 24008 49152" #while true #do for i in $port do isexi ...
- vue中的$nextTick的常用思路
Vue 实现响应式并不是数据发生变化之后 DOM 立即变化,而是按一定的策略进行 DOM 的更新. $nextTick 是在下次 DOM 更新循环结束之后执行延迟回调,在修改数据之后使用 $nextT ...
- sql 数据库
在关系数据库中,最常用的操作就是查询.直线电机推杆 准备数据 为了便于讲解和练习,我们先准备好了一个students表和一个classes表,它们的结构和数据如下: students表存储了学生信息: ...
- PHP ftp_cdup() 函数
定义和用法 ftp_cdup() 函数把当前目录改变为 FTP 服务器上的父目录. 如果成功,该函数返回 TRUE.如果失败,则返回 FALSE. 语法 ftp_cdup(ftp_connection ...
- 管理员技术(六): 硬盘分区及格式化、 新建一个逻辑卷、调整现有磁盘的分区、扩展逻辑卷的大小、添加一个swap分区
一.硬盘分区及格式化 问题: 本例要求熟悉硬盘分区结构,使用fdisk分区工具在磁盘 /dev/vdb 上按以下要求建立分区: 1> 采用默认的 msdos 分区模式 2> ...
- [NOIP模拟15]题解
A.建设城市(city) 这容斥题多难啊你们是怎么考场切掉的啊 首先可以想一下,如果没有k的限制,这题怎么做? 相信你们肯定能看出来是挡板法裸题:m个物品分给n个人,每个人至少一个. 就是$C_{m- ...