input | output |
---|---|
0 3 4 |
6 |
1 /** 2 Create By yzx - stupidboy 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <cstdlib> 7 #include <cmath> 8 #include <deque> 9 #include <vector> 10 #include <queue> 11 #include <iostream> 12 #include <algorithm> 13 #include <map> 14 #include <set> 15 #include <ctime> 16 #include <iomanip> 17 using namespace std; 18 typedef long long LL; 19 typedef double DB; 20 #define For(i, s, t) for(int i = (s); i <= (t); i++) 21 #define Ford(i, s, t) for(int i = (s); i >= (t); i--) 22 #define Rep(i, t) for(int i = (0); i < (t); i++) 23 #define Repn(i, t) for(int i = ((t)-1); i >= (0); i--) 24 #define rep(i, x, t) for(int i = (x); i < (t); i++) 25 #define MIT (2147483647) 26 #define INF (1000000001) 27 #define MLL (1000000000000000001LL) 28 #define sz(x) ((int) (x).size()) 29 #define clr(x, y) memset(x, y, sizeof(x)) 30 #define puf push_front 31 #define pub push_back 32 #define pof pop_front 33 #define pob pop_back 34 #define ft first 35 #define sd second 36 #define mk make_pair 37 38 39 inline int Getint() 40 { 41 int Ret = 0; 42 char Ch = ‘ ‘; 43 bool Flag = 0; 44 while (!(Ch >= ‘0‘ && Ch <= ‘9‘)) 45 { 46 if (Ch == ‘-‘) Flag ^= 1; 47 Ch = getchar(); 48 } 49 while (Ch >= ‘0‘ && Ch <= ‘9‘) 50 { 51 Ret = Ret * 10 + Ch - ‘0‘; 52 Ch = getchar(); 53 } 54 return Flag ? -Ret : Ret; 55 } 56 57 const int N = 255 * 3 + 1, M = 256; 58 int Arr[3], Now[3]; 59 bool Visit[M][M][M], Ans[N]; 60 int Answer; 61 62 inline void Input() 63 { 64 Rep(i, 3) cin >> Arr[i]; 65 Rep(i, 3) swap(Arr[i], Arr[rand() % 3]); 66 } 67 68 inline void Full(int *Can, int x, int y) 69 { 70 int t = min(Can[x], Arr[y] - Can[y]); 71 Can[x] -= t; 72 Can[y] += t; 73 } 74 75 inline void Search(int *Can) 76 { 77 int x = Can[0], y = Can[1], z = Can[2]; 78 if (Visit[x][y][z]) return; 79 Visit[x][y][z] = 1; 80 //cout << x << ‘ ‘ << y << ‘ ‘ << z << endl; 81 Rep(i, 3) 82 if (!Ans[Can[i]]) Ans[Can[i]] = 1; 83 Rep(i, 3) 84 Rep(j, 3) 85 if (i != j && !Ans[Can[i] + Can[j]]) 86 Ans[Can[i] + Can[j]] = 1; 87 if (!Ans[Can[0] + Can[1] + Can[2]]) 88 Ans[Can[0] + Can[1] + Can[2]] = 1; 89 90 int tmp[3]; 91 Rep(i, 3) tmp[i] = Can[i]; 92 Rep(i, 3) 93 Rep(j, 3) 94 if (i != j) 95 { 96 Full(tmp, i, j); 97 Search(tmp); 98 tmp[i] = Can[i]; 99 tmp[j] = Can[j]; 100 } 101 Rep(i, 3) 102 { 103 tmp[i] = Arr[i]; 104 Search(tmp); 105 tmp[i] = Can[i]; 106 } 107 } 108 109 inline void Solve() 110 { 111 Rep(i, 3) 112 if (Arr[i] == 1) 113 { 114 cout << Arr[0] + Arr[1] + Arr[2] << endl; 115 return; 116 } 117 118 Search(Now); 119 120 Answer = 0; 121 For(i, 1, N - 1) 122 { 123 Answer += Ans[i]; 124 //if(Ans[i]) cout << i << endl; 125 } 126 127 cout << Answer << endl; 128 } 129 130 int main() 131 { 132 //SetIO("G"); 133 Input(); 134 Solve(); 135 return 0; 136 }
原文:http://www.cnblogs.com/StupidBoy/p/4979129.html