# 【UOJ#242】【UR#16】破坏蛋糕（计算几何）

UOJ

## 题解

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 100100
const double Pi=acos(-1),eps=1e-7;
{
int x=0;bool t=false;char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')t=true,ch=getchar();
while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
return t?-x:x;
}
struct Node{double x,y;}G[MAX];
double Len(Node a){return sqrt(a.x*a.x+a.y*a.y);}
Node operator+(Node a,Node b){return (Node){a.x+b.x,a.y+b.y};}
Node operator-(Node a,Node b){return (Node){a.x-b.x,a.y-b.y};}
Node operator*(Node a,double b){return (Node){a.x*b,a.y*b};}
double Cross(Node a,Node b){return a.x*b.y-a.y*b.x;}
struct Line{Node p,v;}L[MAX],pL[MAX];
Node Intersection(Line a,Line b)
{
Node c=b.p-a.p;
double t=Cross(b.v,c)/Cross(b.v,a.v);
return a.p+a.v*t;
}
bool Parallel(Line a,Line b){return fabs(Cross(a.v,b.v))<1e-9;}
Node Turn(Node a,double alp){return (Node){a.x*cos(alp)-a.y*sin(alp),a.x*sin(alp)+a.y*cos(alp)};}
int n,id[MAX];double K[MAX];
bool cmpid(int a,int b){return G[a].y>G[b].y;}
int St[MAX],cl[MAX],cr[MAX];
double ang[MAX];
int main()
{
for(int i=1;i<=n+1;++i)
{
L[i].p=(Node){x1,y1};L[i].v=(Node){x2,y2};
L[i].v=L[i].v-L[i].p;pL[i]=L[i];
}
double alpha=Pi/2-atan2(L[n+1].v.y,L[n+1].v.x);
for(int i=1;i<=n+1;++i)L[i].p=Turn(L[i].p,alpha);
for(int i=1;i<=n+1;++i)L[i].v=Turn(L[i].v,alpha);
for(int i=1;i<=n+1;++i)L[i].p=L[i].p-L[n+1].p;
for(int i=1;i<=n;++i)K[i]=L[i].v.y/L[i].v.x;
for(int i=1;i<=n;++i)G[i]=(Node){0,L[i].p.y-K[i]*L[i].p.x};
for(int i=1;i<=n;++i)id[i]=i;
sort(&id[1],&id[n+1],cmpid);
for(int i=1,top=0;i<=n;++i)
{
int x=id[i],l=1,r=top,ret=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(K[x]>K[id[St[mid]]]&&!Parallel(pL[x],pL[id[St[mid]]]))ret=mid,r=mid-1;
else l=mid+1;
}
if(ret)cl[St[ret]]++,cl[i]--;
else St[++top]=i;
}
for(int i=1,top=0;i<=n;++i)
{
int x=id[i],l=1,r=top,ret=0;
while(l<=r)
{
int mid=(l+r)>>1;
if(K[x]<K[id[St[mid]]]&&!Parallel(pL[x],pL[id[St[mid]]]))ret=mid,r=mid-1;
else l=mid+1;
}
if(ret)cr[St[ret]]++,cr[i]--;
else St[++top]=i;
}
for(int i=1;i<=n;++i)cl[i]+=cl[i-1],cr[i]+=cr[i-1];cl[n+1]=cr[n+1]=0;
for(int i=n;~i;--i)
if(cl[i]&&cr[i])putchar(49);
else putchar(48);
return 0;
}

posted @ 2019-07-10 17:30  小蒟蒻yyb  阅读(467)  评论(0编辑  收藏  举报