#include<bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef pair<int,int> par; typedef pair<int, par> para; set<par> vis; queue<para> q; int pa, pb, pc, su, sol, wyn[100009], a1, b1; void pour(int x, int y, int px, int py) { b1 = min(x + y, py); a1 = x + y - b1; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c; para p; cin>>pa>>pb>>pc; cin>>a>>b>>c; su = a + b + c; for(int i=0; i<=pc; i++) wyn[i] = -1; q.push(para(0, par(a, b))); while(!q.empty()) { p = q.front(); q.pop(); if(vis.find(p.se) != vis.end()) continue; vis.insert(p.se); a = p.se.fi; b = p.se.se; c = su - a - b; if(wyn[a] == -1) wyn[a] = p.fi; if(wyn[b] == -1) wyn[b] = p.fi; if(wyn[c] == -1) wyn[c] = p.fi; pour(a, b, pa, pb); if(vis.find(par(a1, b1)) == vis.end()) q.push(para(p.fi+1, par(a1, b1))); pour(a, c, pa, pc); if(vis.find(par(a1, b)) == vis.end()) q.push(para(p.fi+1, par(a1, b))); pour(b, a, pb, pa); if(vis.find(par(b1, a1)) == vis.end()) q.push(para(p.fi+1, par(b1, a1))); pour(b, c, pb, pc); if(vis.find(par(a, a1)) == vis.end()) q.push(para(p.fi+1, par(a, a1))); pour(c, a, pc, pa); if(vis.find(par(b1, b)) == vis.end()) q.push(para(p.fi+1, par(b1, b))); pour(c, b, pc, pb); if(vis.find(par(a, b1)) == vis.end()) q.push(para(p.fi+1, par(a, b1))); } for(int i=0; i<=pc; i++) cout<<wyn[i]<<" "; 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 | #include<bits/stdc++.h> #define fi first #define se second #define pb push_back using namespace std; typedef pair<int,int> par; typedef pair<int, par> para; set<par> vis; queue<para> q; int pa, pb, pc, su, sol, wyn[100009], a1, b1; void pour(int x, int y, int px, int py) { b1 = min(x + y, py); a1 = x + y - b1; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int a, b, c; para p; cin>>pa>>pb>>pc; cin>>a>>b>>c; su = a + b + c; for(int i=0; i<=pc; i++) wyn[i] = -1; q.push(para(0, par(a, b))); while(!q.empty()) { p = q.front(); q.pop(); if(vis.find(p.se) != vis.end()) continue; vis.insert(p.se); a = p.se.fi; b = p.se.se; c = su - a - b; if(wyn[a] == -1) wyn[a] = p.fi; if(wyn[b] == -1) wyn[b] = p.fi; if(wyn[c] == -1) wyn[c] = p.fi; pour(a, b, pa, pb); if(vis.find(par(a1, b1)) == vis.end()) q.push(para(p.fi+1, par(a1, b1))); pour(a, c, pa, pc); if(vis.find(par(a1, b)) == vis.end()) q.push(para(p.fi+1, par(a1, b))); pour(b, a, pb, pa); if(vis.find(par(b1, a1)) == vis.end()) q.push(para(p.fi+1, par(b1, a1))); pour(b, c, pb, pc); if(vis.find(par(a, a1)) == vis.end()) q.push(para(p.fi+1, par(a, a1))); pour(c, a, pc, pa); if(vis.find(par(b1, b)) == vis.end()) q.push(para(p.fi+1, par(b1, b))); pour(c, b, pc, pb); if(vis.find(par(a, b1)) == vis.end()) q.push(para(p.fi+1, par(a, b1))); } for(int i=0; i<=pc; i++) cout<<wyn[i]<<" "; return 0; } |