BZOJ 1857: [Scoi2010]傳送帶【三分】
阿新 • • 發佈:2019-02-20
膜一波大佬啊~~
三分兩個傳送帶的距離,然後相似算一下座標:
#include <cmath> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define db double #define sg string #define ll long long #define rel(i,x,y) for(ll i=(x);i<(y);i++) #define rep(i,x,y) for(ll i=(x);i<=(y);i++) #define red(i,x,y) for(ll i=(x);i>=(y);i--) #define res(i,x) for(ll i=head[x];i;i=nxt[i]) using namespace std; const ll N=1e5+5; const ll Inf=1e18; const db Eps=1e-10; struct node { db x,y; }pt[5]; db p,q,r; db getdis(node p,node q) { return sqrt((p.x-q.x)*(p.x-q.x)+(p.y-q.y)*(p.y-q.y)); } node getpos(ll x,ll y,db len) { db tlen=getdis(pt[x],pt[y]),quo=tlen==0?0:len/tlen; return (node){pt[x].x+(pt[y].x-pt[x].x)*quo,pt[x].y+(pt[y].y-pt[x].y)*quo}; } db f(node x,db len) { node tmp=getpos(3,4,len); return getdis(x,tmp)/r+(getdis(pt[3],pt[4])-len)/q; } db f(db len) { node tmp=getpos(1,2,len); db l=0,r=getdis(pt[3],pt[4]); while(l+Eps<=r) { db lmid=(2*l+r)/3.0,rmid=(l+2*r)/3.0; if(f(tmp,lmid)>=f(tmp,rmid)) l=lmid; else r=rmid; } return len/p+f(tmp,l); } int main() { rep(i,1,4) scanf("%lf%lf",&pt[i].x,&pt[i].y); scanf("%lf%lf%lf",&p,&q,&r); db l=0.0,r=getdis(pt[1],pt[2]); while(l+Eps<=r) { db lmid=(2*l+r)/3.0,rmid=(l+2*r)/3.0; if(f(lmid)>=f(rmid)) l=lmid; else r=rmid; } printf("%.2lf",f(l)); return 0; }