Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
水#include <iostream> #include <string> using namespace std; int getMv(string s1, string s2){ if(s1 == "move"){ if(s2 == "onto") return 0; return 1; } if(s2 == "onto") return 2; return 3; } int main() { int N; cin >> N; int stk[25][25]; int gs[25]; int blk[25]; int h[25]; for(int i = 0; i < N; i++) gs[i] = 1; for(int i = 0; i < N; i++) stk[i][0] = i; for(int i = 0; i < N; i++) blk[i] = i; for(int i = 0; i < N; i++) h[i] = 0; while(1){ string s1, s2; int from, to; cin >> s1; if(s1 == "quit") { for(int i = 0; i < N; i++){ cout << i << ":"; for(int j = 0; j < gs[i]; j++){ cout << " " << stk[i][j]; } cout << endl; } return 0; } cin >> from >> s2 >> to; int mv = getMv(s1, s2); int b1 = blk[from], b2 = blk[to]; int h1 = h[from], h2 = h[to]; if(b1 == b2) continue; switch(mv){ case 0:{ for(int i = h1+1; i < gs[b1]; i++){ int tar = stk[b1][i]; blk[tar] = tar; h[tar] = 0; stk[tar][0] = tar; gs[tar] = 1; } for(int i = h2+1; i < gs[b2]; i++){ int tar = stk[b2][i]; blk[tar] = tar; h[tar] = 0; stk[tar][0] = tar; gs[tar] = 1; } blk[from] = b2; h[from] = h2+1; stk[b2][h2+1] = from; gs[b1] = h1; gs[b2] = h2+2; break; } case 1:{ for(int i = h1+1; i < gs[b1]; i++){ int tar = stk[b1][i]; blk[tar] = tar; h[tar] = 0; stk[tar][0] = tar; gs[tar] = 1; } blk[from] = b2; h[from] = gs[b2]; stk[b2][gs[b2]] = from; gs[b2]++; gs[b1] = h1; break; } case 2:{ for(int i = h2+1; i < gs[b2]; i++){ int tar = stk[b2][i]; blk[tar] = tar; h[tar] = 0; stk[tar][0] = tar; gs[tar] = 1; } for(int i = h1; i < gs[b1]; i++){ int tar = stk[b1][i]; blk[tar] = b2; h[tar] = i-h1+h2+1; stk[b2][h[tar]] = tar; } gs[b2] = h2+1; gs[b2] += gs[b1]-h1; gs[b1] = h1; break; } case 3:{ for(int i = h1; i < gs[b1]; i++){ int tar = stk[b1][i]; blk[tar] = b2; h[tar] = i-h1+gs[b2]; stk[b2][h[tar]] = tar; } gs[b2] += gs[b1]-h1; gs[b1] = h1; break; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator