0%

思路讲解

可以假设顶层木棍不超过1000根。

这句话比较重要。于是我们选择去维护这个顶层木棍,不断用上面的木棍去看这些木棍是不是顶层木棍。

核心代码长这样。

1
2
3
4
5
6
7
8
9
10
11
12
FOR(i,0,N-1){
Line a=A[i];
for(auto it=ans.begin();it!=ans.end();){
Line t=A[*it];
auto nit=next(it);
if(isseginterline(a,t) && isseginterline(t,a)){
ans.erase(it);
}
it=nit;
}
ans.EB(i);
}

AC代码

https://vjudge.net/solution/63275995

心路历程(WA,TLE,MLE……)

思路讲解

image

可以用dij做。搜索做不太了。

先建边,然后再跑dij,会快一些。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
auto check=[&](Line a){
int idx=lower_bound(all(A),Line(a.a,Point(INF,INF)))-A.begin();
bool ok=true;
FOR(i,idx,SZ(A)-1){
Line t=A[i];
if(sgn(t.a.x()-a.b.x())>=0) break;
if(isseginterline(t, a)){
ok=false;
break;
}
}
return ok;
};
vb vis(node.size()+5);
vector<vector<pair<ld,int> > > g(SZ(node)+5);
priority_queue<DIS> pq;
pq.EM(0,0);
FOR(i,0,SZ(node)-1){
FOR(j,i+1,SZ(node)-1){
if(node[i].x()==node[j].x()){
continue;
}
Point a=node[i],b=node[j];
if(check(Line(a,b))){
g[i].emplace_back(abs(a-b),j);
}
}
}

AC代码

https://vjudge.net/solution/63271204

心路历程(WA,TLE,MLE……)

思路讲解

image

详细解释了一下这个式子是怎么来的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// p+tv=q+sw
// (p-q) x w+tv x w = 0
// t=-(p-q)x w/(vxw)
// 传入的是方向式
Point getintersect(Point p,Point v,Point q,Point w){
Point u=p-q;
ld t=cross(w,u)/cross(v,w);
return p+v*t;
}
inline void __(){
Point a,b,c,d;
cin>>a>>b>>c>>d;
Point ab=b-a,cd=d-c;
if(!sgn(cross(ab,cd))){
Point bc=c-b,ad=d-a;
if(!sgn(cross(bc, ad))){
cout<<"LINE\n";
return;
}
cout<<"NONE\n";
return;
}
Point res=getintersect(a, ab, c, cd);
cout<<"POINT "<<fsp(2)<<res.real()<<" "<<res.imag()<<"\n";
}

AC代码

https://vjudge.net/solution/63256517

心路历程(WA,TLE,MLE……)

思路讲解

样例一就是选一条垂线就行。

image

通过样例一不难发现,只要存在一条线与所有的线段相交,那么,就可以了。

因为所有与这条线段相交的点都会投影到这条线的垂线上。

AC代码

https://vjudge.net/solution/63255893

心路历程(WA,TLE,MLE……)

思路讲解

线段树上二分

https://www.luogu.com.cn/article/2a6kvgjo

参考这篇题解。

当然,我们先要枚举一下需要操作几轮。

1
2
3
4
5
6
7
8
9
10
FOR(j,1,64){
if(w>sum){
w-=sum;
ans+=N;
}else{
break;
}
bei*=2;
sum*=2;
}

AC代码

https://www.luogu.com.cn/record/233323384

心路历程(WA,TLE,MLE……)