一句话题意:平面上有 n+1条直线,前 n 条直线把平面分成许多块,这些块有些面积有限,有些面积无限,而第 n+1 条直线不经过前 n 条直线的交点,且一定不和前 n 条直线中的任意一条平行,求第 n+1 条直线被前 n 条直线划分成的 n+1 段中哪些在面积有限的块里,哪些在面积无限的块里。
保证第 n+1 条直线不经过前 n 条直线的交点,且一定不和前 n 条直线中的任意一条平行或重合。
保证第 n+1 条直线不与 x 轴垂直,且对于第 n+1 条直线有
x1<x2,3≤n≤105
,保证
−2×106≤x1,y1,x2,y2≤2×106
。
对于点O所在的区域,所有直线改为左侧为O的有向直线,原题变为每次调整一条直线的方向,维护半平面交的区域是否有限,也就是是否有两条相邻的有向直线转角 >π ,这可以用set解决
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,0x3f,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define MEMx(a,b) memset(a,b,sizeof(a));
#define INF (0x3f3f3f3f)
#define F (1000000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
#define Pr(kcase,ans) printf("Case #%d: %lld\n",kcase,ans);
#define PRi(a,n) For(i,n-1) cout<<a[i]<<' '; cout<<a[n]<<endl;
#define PRi2D(a,n,m) For(i,n) { \
For(j,m-1) cout<<a[i][j]<<' ';\
cout<<a[i][m]<<endl; \
}
#pragma comment(linker, "/STACK:102400000,102400000")
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return ((a-b)%F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll sqr(ll a){return a*a;}
ld sqr(ld a){return a*a;}
double sqr(double a){return a*a;}
const double eps=1e-10;
int dcmp(double x) {
if (fabs(x)<eps) return 0; else return x<0 ? -1 : 1;
}
ld PI = 3.141592653589793238462643383;
class P{
public:
double x,y;
P(double x=0,double y=0):x(x),y(y){}
friend long double dis2(P A,P B){return sqr(A.x-B.x)+sqr(A.y-B.y); }
friend long double Dot(P A,P B) {return A.x*B.x+A.y*B.y; }
friend long double Length(P A) {return sqrt(Dot(A,A)); }
friend long double Angle(P A,P B) {return acos(Dot(A,B) / Length(A) / Length(B) ); }
friend P operator- (P A,P B) { return P(A.x-B.x,A.y-B.y); }
friend P operator+ (P A,P B) { return P(A.x+B.x,A.y+B.y); }
friend P operator* (P A,double p) { return P(A.x*p,A.y*p); }
friend P operator/ (P A,double p) { return P(A.x/p,A.y/p); }
friend bool operator< (const P& a,const P& b) {return dcmp(a.x-b.x)<0 ||(dcmp(a.x-b.x)==0&& dcmp(a.y-b.y)<0 );}
};
P read_point() {
P a;
scanf("%lf%lf",&a.x,&a.y);
return a;
}
bool operator==(const P& a,const P& b) {
return dcmp(a.x-b.x)==0 && dcmp(a.y-b.y) == 0;
}
typedef P V;
double Cross(V A,V B) {return A.x*B.y - A.y*B.x;}
double Area2(P A,P B,P C) {return Cross(B-A,C-A);}
P GetLineIntersection(P p,V v,P Q,V w){
V u = p-Q;
double t = Cross(w,u)/Cross(v,w);
return p+v*t;
}
struct Line{
P p;
V v;
double ang;
Line(){}
Line(P p,V v):p(p),v(v) {ang=atan2(v.y,v.x); }
bool operator<(const Line & L) const {
return ang<L.ang;
}
P point(double a) {
return p+v*a;
}
void reverse() {
p=p+v;
v=P(-v.x,-v.y);
ang=atan2(v.y,v.x);
}
};
#define MAXN (100005+10)
Line l,s[MAXN];
int n;
ld a[MAXN];
multiset <ld> S;
multiset <ld>::iterator it,_it;
vector< pair<P,int> > ins;
int cnt = 0;
int check(ld a,ld b,bool flag=0) {
if (flag) a-=2*PI;
if (dcmp(b-a-PI)>=0) return 1;
return 0;
}
void Insert(ld c) {
multiset <ld>::iterator pre,nex,it;
pre=nex=it= S.insert(c);
bool b1=0,b2=0;
if (pre==S.begin()) pre=--S.end(),b1=1;else --pre;
if (++nex==S.end()) nex=S.begin(),b2=1;
cnt+=check(*pre,*it,b1)+check(*it,*nex,b2)-check(*pre,*nex,b1|b2);
}
void Delete(ld c) {
multiset <ld>::iterator pre,nex,it;
pre=nex=it= S.find(c);
bool b1=0,b2=0;
if (pre==S.begin()) pre=--S.end(),b1=1;else --pre;
if (++nex==S.end()) nex=S.begin(),b2=1;
cnt-=check(*pre,*it,b1)+check(*it,*nex,b2)-check(*pre,*nex,b1|b2);
S.erase(it);
}
void work() {
Rep(i,SI(ins)) {
putchar("01"[cnt==0]);
int k=ins[i].se;
Delete(a[k]);
a[k]+=PI;if (a[k]>PI) a[k]-=2*PI;
Insert(a[k]);
}
putchar("01"[cnt==0]);
puts("");
}
int main()
{
// freopen("uoj242.in","r",stdin);
// freopen(".out","w",stdout);
n=read();
For(i,n+1) {
P A=read_point(),B=read_point();
s[i]=Line(A,B-A);
}
l=s[n+1];
For(i,n) {
if (dcmp(Cross(l.v,s[i].v))<0) s[i].reverse();
a[i]=s[i].ang;
P e=GetLineIntersection(s[i].p,s[i].v,l.p,l.v) ;
ins.pb(mp(e,i));
S.insert(a[i]);
}
sort(ALL(ins));
cnt+=check(*--S.end(),*S.begin(),1);
for(it=S.begin(),_it=++S.begin();_it!=S.end();it=_it,_it++) {
cnt+=check(*it,*_it);
}
work();
return 0;
}