#include <bits/stdc++.h> using namespace std; typedef long long ll; const double INF=INT_MAX; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int L,vk,v0,v1,v2; cin>>L>>vk>>v0>>v1>>v2; int v[3]={v0,v1,v2}; string napis; vector <pair<int,int>> szcz[3]; int ost_sam[3]={-1,-1,-1}; int pocz_szcz; for (int i=0;i<3;i++){ cin>>napis; pocz_szcz=-1; for (int j=0;j<L;j++){ if (napis[j]=='.'){ if (pocz_szcz==-1) pocz_szcz=j; else continue; } else { //była # if (i==2 && j==0){ pocz_szcz=0; } else{ ost_sam[i]=j; if (pocz_szcz!=-1){ szcz[i].push_back({pocz_szcz,j-1}); pocz_szcz=-1; } } } } if (pocz_szcz>=0){ szcz[i].push_back({pocz_szcz,400000}); pocz_szcz=-1; }else{ szcz[i].push_back({L,400000}); pocz_szcz=-1; } } //nie ma nic przed nami double t1,t0,t; if (ost_sam[2]==0 or ost_sam[1]==-1 or (szcz[1].size()>=1 && szcz[1][0].first==0 and ost_sam[0]==-1)){ if (ost_sam[1]>=0) t1=double(ost_sam[1]+1)/(vk-v1); if (ost_sam[0]>=0) t0=double(ost_sam[0]+1)/(vk-v0); cout<<std::setprecision(15)<<max(t1,t0); return 0; } int akt_pas=2; int nr_szcz=0; pair <int,int> s; // double t=0; //kol //t, akt_pas, nr_szcz, nr_szcz0, nr_szcz1, nr_szcz2 priority_queue <tuple<double,int,int,int,int,int>> kol; vector <double> czas_wej_szcz[3]; int ile =max(max(szcz[0].size(),szcz[1].size()),szcz[2].size()); for (int j=0;j<3;j++){ for (int i=0;i<=ile ;i++){ czas_wej_szcz[j].push_back(INF); } } kol.push({0.0,2,0,0,0,0}); int nr_szcz0=0,nr_szcz1=0,nr_szcz2=0; double tb=0,ts=0; double odl=0; while (!kol.empty()) { auto [t,akt_pas,nr_szcz,nr_szcz0,nr_szcz1,nr_szcz2]=kol.top(); kol.pop(); cout<<t<<" "<<akt_pas<<" "<<nr_szcz<<"\n"; t=(-1)*t; if (akt_pas==2){ //Do konca biezacej szczeliny auto [pocz,kon]=szcz[2][nr_szcz1]; odl=kon-pocz; //tb=s/dv tb=odl/(vk-v2); if (kon==400000){ t1=double(ost_sam[1]+1)/(vk-v1); t0=double(ost_sam[0]+1)/(vk-v0); //moze dodawac do kolejki wynikow ? cout<<setprecision(15)<<max(t1,t0); return 0; } ; do { //tylko na 1 - wszystkie mozliwe początki szczelin odl=szcz[1][nr_szcz1].first+(t*(v1-v2)); //Odleglosc ta moze przejechac w czasie s/dv=ts ts=odl/(vk-v1); if (ts<=tb){ if (t+ts<czas_wej_szcz[1][nr_szcz1]){ //Jeśli nas nie było w szczelnie z tak dobrym czasem kol.push({-(t+ts),1,nr_szcz1,nr_szcz0,nr_szcz1,nr_szcz2+1}); czas_wej_szcz[1][nr_szcz1]=t+ts; } } nr_szcz1++; }while ((tb>=ts) and nr_szcz1<szcz[1].size()); }else if (akt_pas==0){ //na 1 }else if (akt_pas==1){ //srodkowy //tylko na 0 i 2 } //podjedz jesli sie da // s=szcz[akt_pas][nr_szcz[akt_pas]]; // t=(s.second-s.first)*(vk-v[akt_pas]); // w1=t*(vk-v1); // if (akt_pas==2 && t*(vk-v1)){ // } } 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 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 151 152 153 154 155 156 157 158 159 160 161 162 | #include <bits/stdc++.h> using namespace std; typedef long long ll; const double INF=INT_MAX; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); int L,vk,v0,v1,v2; cin>>L>>vk>>v0>>v1>>v2; int v[3]={v0,v1,v2}; string napis; vector <pair<int,int>> szcz[3]; int ost_sam[3]={-1,-1,-1}; int pocz_szcz; for (int i=0;i<3;i++){ cin>>napis; pocz_szcz=-1; for (int j=0;j<L;j++){ if (napis[j]=='.'){ if (pocz_szcz==-1) pocz_szcz=j; else continue; } else { //była # if (i==2 && j==0){ pocz_szcz=0; } else{ ost_sam[i]=j; if (pocz_szcz!=-1){ szcz[i].push_back({pocz_szcz,j-1}); pocz_szcz=-1; } } } } if (pocz_szcz>=0){ szcz[i].push_back({pocz_szcz,400000}); pocz_szcz=-1; }else{ szcz[i].push_back({L,400000}); pocz_szcz=-1; } } //nie ma nic przed nami double t1,t0,t; if (ost_sam[2]==0 or ost_sam[1]==-1 or (szcz[1].size()>=1 && szcz[1][0].first==0 and ost_sam[0]==-1)){ if (ost_sam[1]>=0) t1=double(ost_sam[1]+1)/(vk-v1); if (ost_sam[0]>=0) t0=double(ost_sam[0]+1)/(vk-v0); cout<<std::setprecision(15)<<max(t1,t0); return 0; } int akt_pas=2; int nr_szcz=0; pair <int,int> s; // double t=0; //kol //t, akt_pas, nr_szcz, nr_szcz0, nr_szcz1, nr_szcz2 priority_queue <tuple<double,int,int,int,int,int>> kol; vector <double> czas_wej_szcz[3]; int ile =max(max(szcz[0].size(),szcz[1].size()),szcz[2].size()); for (int j=0;j<3;j++){ for (int i=0;i<=ile ;i++){ czas_wej_szcz[j].push_back(INF); } } kol.push({0.0,2,0,0,0,0}); int nr_szcz0=0,nr_szcz1=0,nr_szcz2=0; double tb=0,ts=0; double odl=0; while (!kol.empty()) { auto [t,akt_pas,nr_szcz,nr_szcz0,nr_szcz1,nr_szcz2]=kol.top(); kol.pop(); cout<<t<<" "<<akt_pas<<" "<<nr_szcz<<"\n"; t=(-1)*t; if (akt_pas==2){ //Do konca biezacej szczeliny auto [pocz,kon]=szcz[2][nr_szcz1]; odl=kon-pocz; //tb=s/dv tb=odl/(vk-v2); if (kon==400000){ t1=double(ost_sam[1]+1)/(vk-v1); t0=double(ost_sam[0]+1)/(vk-v0); //moze dodawac do kolejki wynikow ? cout<<setprecision(15)<<max(t1,t0); return 0; } ; do { //tylko na 1 - wszystkie mozliwe początki szczelin odl=szcz[1][nr_szcz1].first+(t*(v1-v2)); //Odleglosc ta moze przejechac w czasie s/dv=ts ts=odl/(vk-v1); if (ts<=tb){ if (t+ts<czas_wej_szcz[1][nr_szcz1]){ //Jeśli nas nie było w szczelnie z tak dobrym czasem kol.push({-(t+ts),1,nr_szcz1,nr_szcz0,nr_szcz1,nr_szcz2+1}); czas_wej_szcz[1][nr_szcz1]=t+ts; } } nr_szcz1++; }while ((tb>=ts) and nr_szcz1<szcz[1].size()); }else if (akt_pas==0){ //na 1 }else if (akt_pas==1){ //srodkowy //tylko na 0 i 2 } //podjedz jesli sie da // s=szcz[akt_pas][nr_szcz[akt_pas]]; // t=(s.second-s.first)*(vk-v[akt_pas]); // w1=t*(vk-v1); // if (akt_pas==2 && t*(vk-v1)){ // } } return 0; } |