ch1 : Mother's Milk


/ Published in: C++
Save to your folder(s)



Copy this code and paste it in your HTML
  1. /*
  2.   NAME : Nursoltan
  3.   PROB : milk3
  4.   LANG : C++
  5.   DATE : 30/06/11 22:49
  6. */
  7. #include <algorithm>
  8. #include <bitset>
  9. #include <cctype>
  10. #include <cmath>
  11. #include <cstdio>
  12. #include <cstdlib>
  13. #include <cstring>
  14. #include <ctime>
  15. #include <sstream>
  16. #include <iostream>
  17. #include <map>
  18. #include <set>
  19. #include <stack>
  20. #include <utility>
  21. #include <queue>
  22.  
  23. using namespace std;
  24.  
  25. #define MAX 100
  26. #define INF INT_MAX
  27. #define eps (1e-9)
  28.  
  29. #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)
  30. #define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)
  31. #define CLR(_x) memset((_x),0,sizeof(_x))
  32. #define SQR(_x) ((_x)*(_x))
  33. #define all(_x) _x.begin(),_x.end()
  34. #define sz(_x) sizeof(_x)
  35.  
  36. #define vc vector<int>
  37. #define pb push_back
  38. #define mp make_pair
  39. #define iss istringstream
  40. #define oss ostringstream
  41. #define px first
  42. #define py second.first
  43. #define pz second.second
  44.  
  45. typedef long long ll;
  46. typedef pair<int,pair<int,int> > point;
  47. int ABS(int _x){ return _x>0?_x:-_x; }
  48.  
  49. map<vector<int> , bool> vis;
  50. vector<int> cap;
  51.  
  52. vector<int> pour(vector<int> a, int i, int j){
  53. int k=min(cap[i],a[i]+a[j]);
  54. a[j]-=max(0,k-a[i]);
  55. a[i]=k;
  56. return a;
  57. }
  58.  
  59. set<int> ret;
  60. set<int>::iterator it;
  61.  
  62. void rec(vector<int> a){
  63. if(vis[a]) return;
  64. if(a[0]==0) ret.insert(a[2]);
  65.  
  66. vis[a]=1;
  67. FOR(i,0,3) FOR(j,0,3) if(i!=j){
  68. rec(pour(a,i,j));
  69. }
  70. }
  71.  
  72. int main()
  73. {
  74. freopen("milk3.in","r",stdin);
  75. freopen("milk3.out","w",stdout);
  76.  
  77. cap.clear();
  78. cap.resize(3);
  79. vector<int> a(3);
  80. cin>>cap[0]>>cap[1]>>cap[2];
  81.  
  82. a[0]=a[1]=0; a[2]=cap[2];
  83. rec(a);
  84.  
  85. for(it=ret.begin(); it!=ret.end(); it++){
  86. if(it!=ret.begin()) cout<<" ";
  87. cout<<(*it);
  88. }
  89. cout<<endl;
  90.  
  91. //system("pause");
  92. return 0;
  93. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.