#include <iostream> #include <vector> #include <queue> #include <algorithm> #include <set> #include <iomanip> int v[3],n,vmax; long double t[3]={1e9,1e9,0}; long double new_time[3]; int a[3]={-1,-1,0}; int b[3]={0,0,1}; char x; std::string road[3]; int main(){ std::ios_base::sync_with_stdio(0); std::cin>>n>>vmax>>v[0]>>v[1]>>v[2]; std::cin>>road[0]>>road[1]>>road[2]; for(int i=0;i<3;i++){ while(b[i]<road[i].size()&&road[i][b[i]]=='#') b[i]++; } long double result=0; while(true){ //std::cout<<"a: "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<std::endl; new_time[0]=1e9; new_time[1]=1e9; new_time[2]=1e9; long double a1b0=(a[1]-b[0])/(long double)(v[0]-v[1]); long double a2b1=(a[2]-b[1])/(long double)(v[1]-v[2]); long double d0=((a[1]+v[1]*t[1])-(b[0]+v[0]*t[1]))/(long double)(vmax-v[0]); if(t[1]<=a1b0) new_time[0]=t[1]-d0; long double d1=((a[2]+v[2]*t[2])-(b[1]+v[1]*t[2]))/(long double)(vmax-v[1]); if(t[2]<=a2b1) new_time[1]=t[2]-d1; //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; long double d=((a[0]+v[0]*t[0])-(b[1]+v[1]*t[0]))/(long double)(vmax-v[1]); //std::cout<<t[1]<<" "<<d2<<" "<<b2a1<<std::endl; int mod=(a[0]+1>=road[0].size()||road[0][a[0]+1]=='.'?1:0); long double b1a0=(b[1]-a[0]-mod)/(long double)(v[0]-v[1]); new_time[1]=std::min(new_time[1],std::max(t[0]-d,b1a0)); long double d2=((a[1]+v[1]*t[1])-(b[2]+v[2]*t[1]))/(long double)(vmax-v[2]); //std::cout<<"d2: "<<d2<<std::endl; mod=(a[1]+1>=road[1].size()||road[1][a[1]+1]=='.'?1:0); long double b2a1=(b[2]-a[1]-mod)/(long double)(v[1]-v[2]); //std::cout<<" "<<t[1]<<" "<<d2<<" "<<b2a1<<std::endl; //if(d2>=0) new_time[2]=std::min(new_time[2],std::max(t[1]-d2,b2a1)); //std::cout<<(b[2]-a[1])<<" "<<(long double)(v[1]-v[2])<<" t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; for(int i=0;i<3;i++){ if(b[i]-a[i]==1) new_time[i]=std::min(new_time[i],t[i]+1/(long double)(vmax-v[i])); } //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; //std::cout<<"b: "<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<std::endl; long double sma=std::min(new_time[0],std::min(new_time[1],new_time[2])); for(int i=0;i<3;i++) if(new_time[i]==sma){ //std::cout<<"track: "<<i<<" a: "<<b[i]<<" time: "<<new_time[i]<<std::endl; if(b[i]<=road[i].size()&&b[i]>0&&road[i][b[i]-1]=='#') result=std::max(result,new_time[i]); t[i]=new_time[i]; a[i]=b[i]; b[i]++; while(b[i]<road[i].size()&&road[i][b[i]]=='#') b[i]++; } //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; if(a[0]==n){ std::cout<<std::fixed<<std::setprecision(20)<<result<<std::endl; return 0; } } return 0; }
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 | #include <iostream> #include <vector> #include <queue> #include <algorithm> #include <set> #include <iomanip> int v[3],n,vmax; long double t[3]={1e9,1e9,0}; long double new_time[3]; int a[3]={-1,-1,0}; int b[3]={0,0,1}; char x; std::string road[3]; int main(){ std::ios_base::sync_with_stdio(0); std::cin>>n>>vmax>>v[0]>>v[1]>>v[2]; std::cin>>road[0]>>road[1]>>road[2]; for(int i=0;i<3;i++){ while(b[i]<road[i].size()&&road[i][b[i]]=='#') b[i]++; } long double result=0; while(true){ //std::cout<<"a: "<<a[0]<<" "<<a[1]<<" "<<a[2]<<" "<<std::endl; new_time[0]=1e9; new_time[1]=1e9; new_time[2]=1e9; long double a1b0=(a[1]-b[0])/(long double)(v[0]-v[1]); long double a2b1=(a[2]-b[1])/(long double)(v[1]-v[2]); long double d0=((a[1]+v[1]*t[1])-(b[0]+v[0]*t[1]))/(long double)(vmax-v[0]); if(t[1]<=a1b0) new_time[0]=t[1]-d0; long double d1=((a[2]+v[2]*t[2])-(b[1]+v[1]*t[2]))/(long double)(vmax-v[1]); if(t[2]<=a2b1) new_time[1]=t[2]-d1; //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; long double d=((a[0]+v[0]*t[0])-(b[1]+v[1]*t[0]))/(long double)(vmax-v[1]); //std::cout<<t[1]<<" "<<d2<<" "<<b2a1<<std::endl; int mod=(a[0]+1>=road[0].size()||road[0][a[0]+1]=='.'?1:0); long double b1a0=(b[1]-a[0]-mod)/(long double)(v[0]-v[1]); new_time[1]=std::min(new_time[1],std::max(t[0]-d,b1a0)); long double d2=((a[1]+v[1]*t[1])-(b[2]+v[2]*t[1]))/(long double)(vmax-v[2]); //std::cout<<"d2: "<<d2<<std::endl; mod=(a[1]+1>=road[1].size()||road[1][a[1]+1]=='.'?1:0); long double b2a1=(b[2]-a[1]-mod)/(long double)(v[1]-v[2]); //std::cout<<" "<<t[1]<<" "<<d2<<" "<<b2a1<<std::endl; //if(d2>=0) new_time[2]=std::min(new_time[2],std::max(t[1]-d2,b2a1)); //std::cout<<(b[2]-a[1])<<" "<<(long double)(v[1]-v[2])<<" t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; for(int i=0;i<3;i++){ if(b[i]-a[i]==1) new_time[i]=std::min(new_time[i],t[i]+1/(long double)(vmax-v[i])); } //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; //std::cout<<"b: "<<b[0]<<" "<<b[1]<<" "<<b[2]<<" "<<std::endl; long double sma=std::min(new_time[0],std::min(new_time[1],new_time[2])); for(int i=0;i<3;i++) if(new_time[i]==sma){ //std::cout<<"track: "<<i<<" a: "<<b[i]<<" time: "<<new_time[i]<<std::endl; if(b[i]<=road[i].size()&&b[i]>0&&road[i][b[i]-1]=='#') result=std::max(result,new_time[i]); t[i]=new_time[i]; a[i]=b[i]; b[i]++; while(b[i]<road[i].size()&&road[i][b[i]]=='#') b[i]++; } //std::cout<<"t: "<<new_time[0]<<" "<<new_time[1]<<" "<<new_time[2]<<" "<<std::endl; if(a[0]==n){ std::cout<<std::fixed<<std::setprecision(20)<<result<<std::endl; return 0; } } return 0; } |