fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. //a represents returning which bucket: into bucket or out of bucket
  4. int sim(int a, int c1,int m1, int c2, int m2){
  5. if(m1+m2>c2){
  6. //pour until b2 full
  7. m1-=(c2-m2);
  8. m2=c2;
  9. }
  10. else{
  11. //pour until b1 empty
  12.  
  13. m2+=m1;
  14. m1=0;
  15. }
  16. if(a==1){
  17. return m2;
  18. }
  19. else{
  20. return m1;
  21. }
  22. }
  23.  
  24. int main() {
  25. int c1,m1,c2,m2,c3,m3;
  26. cin>>c1>>m1>>c2>>m2>>c3>>m3;
  27. for(int i = 1; i<=25; i++){
  28. int temp=m1;
  29. m1=sim(0,c1,m1,c2,m2);
  30. m2=sim(1,c1,temp,c2,m2);
  31. temp=m2;
  32.  
  33. m2=sim(0,c2,m2,c3,m3);
  34. m3=sim(1,c2,temp,c3,m3);
  35. temp=m3;
  36.  
  37. m3=sim(0,c3,temp,c1,m1);
  38.  
  39. m1=sim(1, c3,temp,c1,m1);
  40.  
  41.  
  42. }
  43. cout<<m1<<endl<<m2<<endl<<m3<<endl;
  44. return 0;
  45. }
Success #stdin #stdout 0s 5316KB
stdin
10 3
11 4
12 5
stdout
10
0
2