果然我还是太菜了,爆了一天才过。。。。隔壁肉丝都不知道喊了多少句哎╮(╯▽╰)╭我又A了什么傻逼题(然鹅就是wf和国集的题QWQ)
其实这个题就是个裸题,但是我就是不会。。。
这个题第一步就是明显的旋转坐标系(不会的百度),注意要先平移坐标系再旋转
然后问题就变成x轴上下有一些线段,考虑覆盖长度为L的一段区间,看看区间内最接近x轴的线段的长度和(也可以直接按题意理解,好像更好懂)
线段是斜着的很难搞,但是假如覆盖了l~r的区间,那么也可以通过三角函数搞出线段长度
可以先弄一个类似离散化的东西,我的意思是每个线段的左右端点的x坐标为断点,相邻x坐标之间可以看成一段(大概就是这样不懂评论我)
主要问题在处理出每一段最接近x轴的线段是那一条,假如搞定了这个东西,我们可以正反枚举每个段,然后能要段就要,再加上下一个段的一部分更新答案,这个双指针扫一下就好
考虑按端点的x坐标上扫描线,对于线段有一个关键的性质,就是线段不相交,这里隐含着这么一个东西:假如线段u的左端点的x坐标较小,线段v的左端点在线段u的上方/下方,直到u被删除线段的上下关系都是不变的,否则线段就相交了
换句话说,不相交满足对于在任意一条线段的左右端点x坐标框住的区间中,任意一条线段和这一条线段的上下关系不变
那么有这个东西就可以做了,用set维护一下上方最下的线段和下方最上的线段即可
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef long double LD;
const int _=1e2;
const int maxn=1e4+_;
const LD eps=1e-;
LD sqr(LD x){return x*x;}
int n; struct point{LD x,y; point(){} point(LD X,LD Y){x=X,y=Y;}};
LD getdis(point p1,point p2){return sqrt(sqr(p1.x-p2.x)+sqr(p1.y-p2.y));}
LD slope(point p1,point p2){return (p2.y-p1.y)/(p2.x-p1.x);}
LD multi(point p1,point p2,point p0)
{
LD x1,y1,x2,y2;
x1=p1.x-p0.x;
y1=p1.y-p0.y;
x2=p2.x-p0.x;
y2=p2.y-p0.y;
return x1*y2-x2*y1;
} //------------------------------------------------def----------------------------------------------------- struct board
{
point A,B;
LD g;//长度变化的比值 1/cos
void getg(){g=getdis(A,B)/fabs(A.x-B.x);}
}b[maxn];bool cmp(board b1,board b2){return b1.A.y<b2.A.y;}
bool bbbbcmp(board b1,board b2){return b1.A.x<b2.A.x;} LD co,si;
point rot(point p){return point(p.x*co-p.y*si,p.y*co+p.x*si);}
void rotate()
{
LD d=getdis(b[n+].A,b[n+].B);
co=fabs(b[n+].A.x-b[n+].B.x)/d;
si=fabs(b[n+].A.y-b[n+].B.y)/d;
if(b[n+].A.x<b[n+].B.x&&b[n+].A.y<b[n+].B.y)si=-si; for(int i=;i<=n;i++)
{
b[i].A.x-=b[n+].A.x,b[i].A.y-=b[n+].A.y;
b[i].B.x-=b[n+].A.x,b[i].B.y-=b[n+].A.y; b[i].A=rot(b[i].A);
b[i].B=rot(b[i].B);
if(b[i].A.x>b[i].B.x)swap(b[i].A,b[i].B);
b[i].getg(); // printf("%.10Lf %.10Lf %.10Lf %.10Lf\n",b[i].A.x,b[i].A.y,b[i].B.x,b[i].B.y);
}
} //---------------------------------------------------rotate------------------------------------------------- LD xx[*maxn];int xlen;
bool xx_cmp(LD x1,LD x2){return x1<x2;}
int up[*maxn],dp[*maxn];//xx[i]~xx[i-1]这一段被那条线段覆盖着 struct seg
{
int id;
seg(){} seg(int ID){id=ID;}
friend bool operator <(seg s1,seg s2)
{
int x=s1.id,y=s2.id;
if(x<y)return multi(b[x].B,b[y].A,b[x].A)>;
else return multi(b[y].B,b[x].A,b[y].A)<;
}
friend bool operator >(seg s1,seg s2)
{
int x=s1.id,y=s2.id;
if(x<y)return multi(b[x].B,b[y].A,b[x].A)<;
else return multi(b[y].B,b[x].A,b[y].A)>;
}
};set< seg,less<seg> >us;set< seg,greater<seg> >ds; struct qq{int op,p;seg s; qq(){} qq(int OP,int P,seg S){op=OP,p=P,s=S;}}uq[*maxn],dq[*maxn];int uqlen,dqlen;
bool qqqqcmp(qq q1,qq q2){return q1.p==q2.p?q1.op>q2.op:q1.p<q2.p;} int lb(LD d)
{
int l=,r=xlen;
while(l<=r)
{
int mid=(l+r)/;
if(fabs(xx[mid]-d)<=eps)return mid;
if(xx[mid]>d)r=mid-;
else l=mid+;
}
}
void cover(int l1,int r1,int l2,int r2)
{
sort(b+l1,b+r1+,bbbbcmp);
sort(b+l2,b+r2+,bbbbcmp);
uqlen=dqlen=;
for(int i=l1;i<=r1;i++)
{
uq[++uqlen]=qq( ,lb(b[i].A.x)+,seg(i));
uq[++uqlen]=qq(-,lb(b[i].B.x),seg(i));
}
for(int i=l2;i<=r2;i++)
{
dq[++dqlen]=qq( ,lb(b[i].A.x)+,seg(i));
dq[++dqlen]=qq(-,lb(b[i].B.x),seg(i));
} us.clear(),ds.clear();
sort(uq+,uq+uqlen+,qqqqcmp);
sort(dq+,dq+dqlen+,qqqqcmp);
int utp=,dtp=;
for(int i=;i<=xlen;i++)
{
while(utp<=uqlen&&uq[utp].p==i&&uq[utp].op==)us.insert(uq[utp].s),utp++;
while(dtp<=dqlen&&dq[dtp].p==i&&dq[dtp].op==)ds.insert(dq[dtp].s),dtp++; if(!us.empty())up[i]=(*us.begin()).id; else up[i]=-;
if(!ds.empty())dp[i]=(*ds.begin()).id; else dp[i]=-; while(utp<=uqlen&&uq[utp].p==i&&uq[utp].op==-)us.erase(uq[utp].s),utp++;
while(dtp<=dqlen&&dq[dtp].p==i&&dq[dtp].op==-)ds.erase(dq[dtp].s),dtp++;
}
} //-----------------------------------------------cover------------------------------------------------------ int main()
{
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=;i<=n+;i++)
scanf("%Lf%Lf%Lf%Lf",&b[i].A.x,&b[i].A.y,&b[i].B.x,&b[i].B.y);
scanf("%Lf",&b[n+].g);
if(b[n+].A.x>b[n+].B.x)swap(b[n+].A,b[n+].B);
rotate(); //....step1....... int pp=n+; sort(b+,b+n+,cmp);
xlen=;
for(int i=;i<=n;i++)
{
if(b[i].A.y>&&pp==n+)pp=i;
xx[++xlen]=b[i].A.x;
xx[++xlen]=b[i].B.x;
}
sort(xx+,xx+xlen+);
int tp=;
for(int j=;j<=xlen;j++)
if(fabs(xx[j]-xx[tp])>eps)xx[++tp]=xx[j];
xlen=tp;
cover(pp,n,,pp-); //....step2....... LD ans=,sum=;
int j=;
for(int i=;i<=xlen;i++)
{
while(j<xlen&&(xx[j+]-xx[i-])<=b[n+].g)
{
j++;
if(up[j]!=-)sum+=(xx[j]-xx[j-])*b[up[j]].g;
if(dp[j]!=-)sum+=(xx[j]-xx[j-])*b[dp[j]].g;
}
LD num=;
if(j<xlen)
{
if(up[j+]!=-)num+=min(xx[j+]-xx[j],b[n+].g-(xx[j]-xx[i-]))*b[up[j+]].g;
if(dp[j+]!=-)num+=min(xx[j+]-xx[j],b[n+].g-(xx[j]-xx[i-]))*b[dp[j+]].g;
}
ans=max(ans,sum+num);
if(up[i]!=-)sum-=(xx[i]-xx[i-])*b[up[i]].g;
if(dp[i]!=-)sum-=(xx[i]-xx[i-])*b[dp[i]].g; // printf("%.10Lf %.10Lf %.10Lf\n",xx[i]-xx[i-1],b[up[i]].g,b[dp[i]].g);
}
j=xlen;sum=;
for(int i=xlen;i>;i--)
{
while(j>&&(xx[i]-xx[j-])<=b[n+].g)
{
if(up[j]!=-)sum+=(xx[j]-xx[j-])*b[up[j]].g;
if(dp[j]!=-)sum+=(xx[j]-xx[j-])*b[dp[j]].g;
j--;
}
LD num=;
if(j>)
{
if(up[j]!=-)num+=min(xx[j]-xx[j-],b[n+].g-(xx[i]-xx[j]))*b[up[j]].g;
if(dp[j]!=-)num+=min(xx[j]-xx[j-],b[n+].g-(xx[i]-xx[j]))*b[dp[j]].g;
}
ans=max(ans,sum+num);
if(up[i]!=-)sum-=(xx[i]-xx[i-])*b[up[i]].g;
if(dp[i]!=-)sum-=(xx[i]-xx[i-])*b[dp[i]].g;
} printf("%.10Lf\n",ans);
// break;
//....step3.......
} return ;
}