原题:
我的代码:
1 #include<iostream> 2 #include<set> 3 #include<queue> 4 5 6 using namespace std; 7 #define di queue<int> 8 9 di card1; 10 di card2; 11 int k1[12]; 12 int k2[12]; 13 set<di> vis; 14 15 void move(di &a,di&b) 16 { 17 if (a.front() > b.front()) 18 { 19 a.push(b.front()); 20 b.pop(); 21 a.push(a.front()); 22 a.pop(); 23 } 24 else 25 { 26 b.push(a.front()); 27 a.pop(); 28 b.push(b.front()); 29 b.pop(); 30 } 31 } 32 33 34 35 int main() 36 { 37 38 int n, n1, n2; 39 cin >> n; 40 cin >> n1; 41 for (int i = 0; i < n1; i++) 42 { 43 cin >> k1[i]; 44 card1.push(k1[i]); 45 } 46 cin >> n2; 47 for (int i = 0; i < n2; i++) 48 { 49 cin >> k2[i]; 50 card2.push(k2[i]); 51 } 52 53 int cycle = 0; 54 int win = 0; 55 int ans = 0; 56 while (1) 57 { 58 if (ans == 1e4) 59 { 60 cycle = 1; 61 ans = -1; 62 break; 63 } 64 move(card1, card2); 65 ans++; 66 if (card1.empty() ) 67 { 68 cycle = 0; 69 win = 2; 70 break; 71 } 72 if (card2.empty()) 73 { 74 cycle = 0; 75 win = 1; 76 break; 77 } 78 } 79 if (cycle) 80 { 81 cout << ans << endl; 82 } 83 else 84 { 85 cout << ans <<' '<<win<< endl; 86 } 87 return 0; 88 }