#include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back #define gcu getchar_unlocked using namespace std; typedef pair<int,int> pp; typedef long double ld; const ld eps=1e-10; void read(vector<pp> &v) { string s; cin>>s; s+="."; int last=-1,n=(int)s.size(); for(int i=1;i<n;++i) { char I = s[i]; if(I=='.') { if(last!=-1) { v.pb(mp(last,i-1)); last=-1; } } if(I=='#') { if(last==-1) { last=i; } } } } struct pos { ld ti; int x,y; }; bool operator<(const pos &a,const pos &b) { return (a.ti>b.ti) || (a.ti==b.ti && a.y>b.y) || (a.ti==b.ti && a.y==b.y && a.x>b.x); } void out(ld wyn) { cout<<setprecision(15)<<fixed<<wyn<<endl; exit(0); } int main() { int n,v0,v1,v2,v3; scanf("%d%d%d%d%d",&n,&v0,&v1,&v2,&v3); vector<pp> a1,a2,a3; read(a1); read(a2); read(a3); // for(auto I : a1) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); // for(auto I : a2) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); // for(auto I : a3) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); vector<ld> c1(a1.size(),1000000000.0),c2(a2.size(),1000000000.0),c3(a3.size(),1000000000.0); ld wyn=1000000000.0; priority_queue<pos> pq; if(!a1.empty()) pq.push({((ld)(a1[0].ff-1))/(v0-v1),1,0}); if(!a2.empty()) pq.push({((ld)(a2[0].ff-1))/(v0-v2),2,0}); if(!a3.empty()) pq.push({((ld)(a3[0].ff-1))/(v0-v3),3,0}); // printf("11\n"); while(!pq.empty()) { pos tmp=pq.top(); pq.pop(); ld ti=tmp.ti; // printf("> %Lf %d %d\n",ti,tmp.x,tmp.y); if(tmp.x==1) { if(abs(c1[tmp.y]-1000000000.0)<eps) c1[tmp.y]=ti; else continue; // printf("kk\n"); int siz=(int)a2.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a1[tmp.y].ff-a2[i].ff)/(v2-v1); // printf("inter %d: %Lf\n",i,inter); if(inter>=ti) pq.push({inter,2,i}); } siz=(int)a1.size(); // for(int i=0;i<siz;++i) // { // } } if(tmp.x==2) { if(abs(c2[tmp.y]-1000000000.0)<eps) c2[tmp.y]=ti; else continue; int siz=(int)a1.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a2[tmp.y].ff-a1[i].ff)/(v1-v2); if(inter<ti) continue; pq.push({inter,1,i}); } siz=(int)a3.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a2[tmp.y].ff-a3[i].ff)/(v3-v2); if(inter<ti) continue; pq.push({inter,3,i}); } } if(tmp.x==3) { if(abs(c3[tmp.y]-1000000000.0)<eps) c3[tmp.y]=ti; else continue; int siz=(int)a2.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a3[tmp.y].ff-a2[i].ff)/(v2-v3); if(inter<ti) continue; pq.push({inter,2,i}); } } } for(int i=0;i<(int)a1.size();++i) { // printf(">%d %Lf\n",i,c1[i]); ld ti=c1[i]; ld ot=ti+(!a2.empty() ? max((ld)0,((ld)a1[i].ff-a2.back().ss-2-ti*(v2-v1))/(v2-v1)) : (ld)0); // printf("%Lf\n",ot); ot+=max({(ld)0,!a1.empty() ? ((ld)a1.back().ss+2-a1[i].ff+ot*(v1-v1))/(v0-v1) : 0.0,!a2.empty() ? ((ld)a2.back().ss+2-a1[i].ff+ot*(v2-v1))/(v0-v2) : 0.0, !a3.empty() ? ((ld)a3.back().ss+2-a1[i].ff+ot*(v3-v1))/(v0-v3) : 0.0}); wyn=min(wyn,ot); // printf("%Lf\n",wyn); } for(int i=0;i<(int)a2.size();++i) { // printf(">>%d %Lf\n",i,c2[i]); ld ti=c2[i]; ld ot=ti+(!a3.empty() ? max((ld)0,((ld)a2[i].ff-a3.back().ss-2-ti*(v3-v2))/(v3-v2)) : (ld)0); // printf("%Lf\n",ot); ot+= max({(ld)0,!a1.empty() ? ((ld)a1.back().ss+2-a2[i].ff + ot*(v1-v2))/(v0-v1) : 0.0,!a2.empty() ? ((ld)a2.back().ss+2-a2[i].ff + ot*(v2-v2))/(v0-v2) : 0.0, !a3.empty() ? ((ld)a3.back().ss+2-a2[i].ff + ot*(v3-v2))/(v0-v3) : 0.0}); // printf("%Lf\n",ot); wyn=min(wyn,ot); } printf("%.15Lf\n",wyn); }
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | #include<bits/stdc++.h> #define ff first #define ss second #define mp make_pair #define pb push_back #define gcu getchar_unlocked using namespace std; typedef pair<int,int> pp; typedef long double ld; const ld eps=1e-10; void read(vector<pp> &v) { string s; cin>>s; s+="."; int last=-1,n=(int)s.size(); for(int i=1;i<n;++i) { char I = s[i]; if(I=='.') { if(last!=-1) { v.pb(mp(last,i-1)); last=-1; } } if(I=='#') { if(last==-1) { last=i; } } } } struct pos { ld ti; int x,y; }; bool operator<(const pos &a,const pos &b) { return (a.ti>b.ti) || (a.ti==b.ti && a.y>b.y) || (a.ti==b.ti && a.y==b.y && a.x>b.x); } void out(ld wyn) { cout<<setprecision(15)<<fixed<<wyn<<endl; exit(0); } int main() { int n,v0,v1,v2,v3; scanf("%d%d%d%d%d",&n,&v0,&v1,&v2,&v3); vector<pp> a1,a2,a3; read(a1); read(a2); read(a3); // for(auto I : a1) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); // for(auto I : a2) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); // for(auto I : a3) printf("(%d %d), ",I.ff,I.ss); // printf("\n"); vector<ld> c1(a1.size(),1000000000.0),c2(a2.size(),1000000000.0),c3(a3.size(),1000000000.0); ld wyn=1000000000.0; priority_queue<pos> pq; if(!a1.empty()) pq.push({((ld)(a1[0].ff-1))/(v0-v1),1,0}); if(!a2.empty()) pq.push({((ld)(a2[0].ff-1))/(v0-v2),2,0}); if(!a3.empty()) pq.push({((ld)(a3[0].ff-1))/(v0-v3),3,0}); // printf("11\n"); while(!pq.empty()) { pos tmp=pq.top(); pq.pop(); ld ti=tmp.ti; // printf("> %Lf %d %d\n",ti,tmp.x,tmp.y); if(tmp.x==1) { if(abs(c1[tmp.y]-1000000000.0)<eps) c1[tmp.y]=ti; else continue; // printf("kk\n"); int siz=(int)a2.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a1[tmp.y].ff-a2[i].ff)/(v2-v1); // printf("inter %d: %Lf\n",i,inter); if(inter>=ti) pq.push({inter,2,i}); } siz=(int)a1.size(); // for(int i=0;i<siz;++i) // { // } } if(tmp.x==2) { if(abs(c2[tmp.y]-1000000000.0)<eps) c2[tmp.y]=ti; else continue; int siz=(int)a1.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a2[tmp.y].ff-a1[i].ff)/(v1-v2); if(inter<ti) continue; pq.push({inter,1,i}); } siz=(int)a3.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a2[tmp.y].ff-a3[i].ff)/(v3-v2); if(inter<ti) continue; pq.push({inter,3,i}); } } if(tmp.x==3) { if(abs(c3[tmp.y]-1000000000.0)<eps) c3[tmp.y]=ti; else continue; int siz=(int)a2.size(); for(int i=0;i<siz;++i) { ld inter=((ld)a3[tmp.y].ff-a2[i].ff)/(v2-v3); if(inter<ti) continue; pq.push({inter,2,i}); } } } for(int i=0;i<(int)a1.size();++i) { // printf(">%d %Lf\n",i,c1[i]); ld ti=c1[i]; ld ot=ti+(!a2.empty() ? max((ld)0,((ld)a1[i].ff-a2.back().ss-2-ti*(v2-v1))/(v2-v1)) : (ld)0); // printf("%Lf\n",ot); ot+=max({(ld)0,!a1.empty() ? ((ld)a1.back().ss+2-a1[i].ff+ot*(v1-v1))/(v0-v1) : 0.0,!a2.empty() ? ((ld)a2.back().ss+2-a1[i].ff+ot*(v2-v1))/(v0-v2) : 0.0, !a3.empty() ? ((ld)a3.back().ss+2-a1[i].ff+ot*(v3-v1))/(v0-v3) : 0.0}); wyn=min(wyn,ot); // printf("%Lf\n",wyn); } for(int i=0;i<(int)a2.size();++i) { // printf(">>%d %Lf\n",i,c2[i]); ld ti=c2[i]; ld ot=ti+(!a3.empty() ? max((ld)0,((ld)a2[i].ff-a3.back().ss-2-ti*(v3-v2))/(v3-v2)) : (ld)0); // printf("%Lf\n",ot); ot+= max({(ld)0,!a1.empty() ? ((ld)a1.back().ss+2-a2[i].ff + ot*(v1-v2))/(v0-v1) : 0.0,!a2.empty() ? ((ld)a2.back().ss+2-a2[i].ff + ot*(v2-v2))/(v0-v2) : 0.0, !a3.empty() ? ((ld)a3.back().ss+2-a2[i].ff + ot*(v3-v2))/(v0-v3) : 0.0}); // printf("%Lf\n",ot); wyn=min(wyn,ot); } printf("%.15Lf\n",wyn); } |