【题意分析】

  给你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 ;
}

最新文章

  1. 在Ubuntu Server 14.04中搭建FTP服务器(VMWare)
  2. 2015ACM/ICPC亚洲区长春站
  3. 基于Eclipse+Cordova的Android Hybrid应用开发环境搭建
  4. nodejs的第三天学习笔记
  5. Jquery,ajax返回json数据后呈现到html页面的$.post方式。
  6. .net 实现 URL重写,伪静态(方法一)
  7. perf
  8. nginx服务器绑定域名和设置根目录
  9. Azure SQL 数据库最新版本现已提供预览版
  10. .net 非对称加密
  11. poj Hotel 线段树
  12. Caused by:org.hibernate.DuplicateMappingException:Duplicate class/entity/ mapping
  13. Asp.Net Core 2.0 项目实战(11) 基于OnActionExecuting全局过滤器,页面操作权限过滤控制到按钮级
  14. 3.24网络攻防选拔题部分write up
  15. python2.7安装django1.8后提示django-admin.py命令不存在
  16. 为opencv添加contrib库
  17. SQL 游标的存储过程示例
  18. faker php测试数据库生成2
  19. UVA-12558 Egyptian Fractions (HARD version) (IDA* 或 迭代加深搜索)
  20. 腾讯云HTTPS设置管理

热门文章

  1. 通信矩阵转DBC
  2. Fatal error compiling: invalid target release: 11 -&gt; [Help 1]
  3. 2.java中c#中statc 静态调用不同之处、c#的静态构造函数和java中的构造代码块、静态代码块
  4. redis缓存的安装和使用(转)
  5. 获取本机IP,本机名称
  6. asp.net core Mvc 增删改查
  7. 6380. 【NOIP2019模拟2019.10.06】小w与最长路(path)
  8. h5判断设备是ios还是android
  9. renren-fast-vue-动态路由
  10. BZOJ 2326: [HNOI2011]数学作业(矩阵乘法)