标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1191 Accepted Submission(s): 785
1 #include <iostream> 2 #include <algorithm> 3 #include <queue> 4 #include <cstring> 5 #include <cstdio> 6 #include <vector> 7 #include <string> 8 #include <iterator> 9 #include <cmath> 10 #include <deque> 11 #include <stack> 12 #include <cctype> 13 using namespace std; 14 15 const int N = 70; 16 const int INF = 0xfffffff; 17 18 typedef long long ll; 19 typedef long double ld; 20 21 #define INFL 0x7fffffffffffffffLL 22 #define met(a, b) memset(a, b, sizeof(a)) 23 #define rep(c, a, b) for (int c = a; c < b; c++) 24 #define nre(c, a, b) for (int c = a; c > b; c--) 25 26 //h(n) = ( (4*n-2) / (n+1) ) * h(n-1); 27 bool hanoi (int n, int a[], int c[], int b[]); 28 29 int main () 30 { 31 int t; 32 cin >> t; 33 while (t--) 34 { 35 int a[N], b[N], c[N]; 36 int n, x1, x2, x3; cin >> n; 37 cin >> x1; rep (i, 0, x1) cin >> a[i]; 38 cin >> x2; rep (i, 0, x2) cin >> b[i]; 39 cin >> x3; rep (i, 0, x3) cin >> c[i]; 40 a[x1] = b[x2] = c[x3] = -1; 41 42 if (hanoi (n, a, c, b)) cout << "true" << endl; 43 else cout << "false" << endl; 44 } 45 return 0; 46 } 47 48 bool hanoi (int n, int a[], int c[], int b[]) 49 { 50 if (b[0] == n) return false; 51 else if (a[0] == n) return hanoi(n - 1, a + 1, b, c); 52 else if (c[0] == n) return hanoi(n - 1, b, c + 1, a); 53 return true; 54 }
标签:
原文地址:http://www.cnblogs.com/darkdomain/p/4383241.html