【题意分析】

  给你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题解的更多相关文章

  1. 【BZOJ1007】水平可见直线(单调栈)

    [BZOJ1007]水平可见直线(单调栈) 题解 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为 可见的 ...

  2. 【BZOJ1007】[HNOI2008]水平可见直线 半平面交

    [BZOJ1007][HNOI2008]水平可见直线 Description 在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为可见 ...

  3. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  4. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  5. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  6. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  7. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  8. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  9. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

随机推荐

  1. Async Clipboard AP

    转自奇舞周刊,个人学习记录,侵权删 编者按:本文作者李松峰,资深技术图书译者,翻译出版过40余部技术及交互设计专著,现任360奇舞团高级前端开发工程师,360前端技术委员会委员.W3C AC代表 如果 ...

  2. SQL的判断重复新增或者修改

    <insert id="insertTankStatisticData" parameterType="java.util.Map"> <se ...

  3. vue 绑定 class 和 内联样式(style)

    <div id="app31"> <!--多个属性 ,号隔开--> <!-- v-bind:style="{fontSize: fontSi ...

  4. 阿里云HBase全新发布X-Pack NoSQL数据库再上新台阶

    一.八年双十一,造就国内最大最专业HBase技术团队 阿里巴巴集团早在2010开始研究并把HBase投入生产环境使用,从最初的淘宝历史交易记录,到蚂蚁安全风控数据存储.持续8年的投入,历经8年双十一锻 ...

  5. 【LeetCode 8】字符串转换整数 (atoi)

    题目链接 [题解] 注意越界的处理就好 简单题 还有.. 正的-2^31不能由2^31取相反数得到,因为正的int最多到2^31-1 [代码] class Solution { public: boo ...

  6. Android中TextView不获取焦点可以实现跑马灯的效果

    之前在网上找了很多关于TextView的跑马灯效果实现的例子,实现起来都存在一些问题,例如一种是完全重画一个跑马灯,还有就是只设置TextView的相关属性使其具有跑马灯的效果,总的来说这两种方法都是 ...

  7. 思维构造+匹配——cf1199E

    直接枚举每条边,如果边加到图中后还是个匹配图,就直接加,反之就不加 这样加完所有边后,剩下的点必定可以组成一个独立集:因为如果剩下的点中还有互相匹配的,那么这对点应该在加边时就被算到匹配图中 所以要么 ...

  8. 管理员技术(三): 配置静态网络地址、 使用yum软件源 、 升级Linux内核、查找并处理文件、查找并提取文件内容

    一. 配置静态网络地址 目标: 本例要求为虚拟机 server 配置以下静态地址参数: 1> 主机名:server0.example.com    2> IP地址:172.25.0.11  ...

  9. android API版本对应的系统版本及Android获取手机和系统版本等信息的代码

    学了这么久的Android,竟然一直对其API对应的名称关系一值搞不清楚,现在网上认真看了下资料,转载一个觉得写得不错的作者的文章,记下来: [背景] 之前折腾android期间,慢慢地知道了,And ...

  10. JAVA学习之环境搭建

    了解到JAVA语言的跨平台性的原理是通过在不同的操作系统中安装对应版本的的JAVA虚拟机(JVM)实现 开发JAVA前必须先搭建JAVA环境: 1.JAVA开发工具包JDK(JAVA DEVELOPM ...