【题意分析】

  给你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. 网络基础之TCP/IP协议族

    一.TCP/IP协议族 1.什么是协议? 计算机与网络设备相互通信依赖于相同的方法,比如,双方通信基于何种语言等.而把通信所依赖的这一切方法统称为规则,而我们就把这种规则称为协议. 协议中存在各种各样 ...

  2. html常用标签梳理

    标签的语法 标签由英文尖括号<和>括起来,如<html>就是一个标签. html中的标签一般都是成对出现的,分开始标签和结束标签.结束标签比开始标签多了一个/. 如: (1)& ...

  3. AcWing 197. 阶乘分解 (筛法)打卡

    给定整数 N ,试把阶乘 N! 分解质因数,按照算术基本定理的形式输出分解结果中的 pipi 和 cici 即可. 输入格式 一个整数N. 输出格式 N! 分解质因数后的结果,共若干行,每行一对pi, ...

  4. ZROI week1

    \[ZROI day1\] \[Grid\] 题目描述 给定一个矩阵,小写字母,求一条路径使得从\((1,1) -> (n,m)\),字典序最小,并且每次只能向右或者向下. 题解 先考虑如果没有 ...

  5. 堆、栈、方法区、静态代码块---Java

    java 堆.栈.方法区 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令) 2.jvm只有一个堆区(heap)被所有线程共享,堆中不存放基 ...

  6. mongodb导入csv

    主要介绍使用自带工具mongoimport工具将 CSV 格式数据导入到 MongoDB 的详细过程. 由于官方提供了mongoimport工具,所以实际上导入 CSV 格式数据的过程非常简单,再次体 ...

  7. Java-Class-C:cn.hutool.core.date.DateUtil

    ylbtech-Java-Class-C:cn.hutool.core.date.DateUtil 1.返回顶部   2.返回顶部 1.1. import cn.hutool.core.date.Da ...

  8. 2 USB标准请求

    2 USB标准设备请求的结构 2.1 标准请求 bmRequestType 的D6~D5为00的请求,USB协议定义了11个标准请求(bRequest),其名字与相应的bRequest的值如下表: 表 ...

  9. CentOS 7 启用中文输入法

    $HOME/.xinitrc LANG="zh_CN.UTF-8" exec startxfce4

  10. java IO 类概述表

    列举常用的类方便查看,温故知新! byte input byte output character input character output Basic InputStream OutputStr ...