UVA - 101 The Blocks Problem
2014-10-03 14:07
381 查看
题目大意:按照四个移动规则来移动箱子
解题思路:用结构体来存储箱子,并记录箱子的数量
解题思路:用结构体来存储箱子,并记录箱子的数量
#include<cstdio> #include<cstring> struct block { int B[50]; int number; }; int main() { block B[50];//存储数据 int test; scanf("%d", &test); for(int i = 0; i < test ;i++) { B[i].B[0] = i;//赋值 B[i].number = 1; } char str[10]; while(scanf("%s", str) != EOF && str[0] != 'q') { int num1; scanf("%d",&num1); char str2[10]; scanf("%s",str2); int num2; scanf("%d", &num2); int mark1 = -1; int mark2; for(int i = 0; i < test; i++) { for(int j = 0; j < B[i].number; j++) if(B[i].B[j] == num2) { mark1 = i; mark2 = j; } if(mark1 != -1) break; } int mark3 = -1; int mark4; for(int i = 0; i < test; i++) { for(int j = 0; j < B[i].number; j++) if(B[i].B[j] == num1) { mark3 = i; mark4 = j; } if(mark3 != -1) break; } if(mark1 == mark3) { continue; } if(str[0] == 'm') { for(int i = mark4 + 1; i < B[mark3].number; i++) { B[B[mark3].B[i]].B[0] = B[mark3].B[i]; B[B[mark3].B[i]].number = 1; } B[mark3].number = mark4; if(str2[1] == 'n') { for(int i = mark2 + 1; i < B[mark1].number; i++) { B[B[mark1].B[i]].B[0] = B[mark1].B[i]; B[B[mark1].B[i]].number = 1; } B[mark1].B[mark2 + 1] = num1; B[mark1].number = mark2 + 2; } else { B[mark1].B[B[mark1].number] = num1; B[mark1].number++; } } else { if(str2[1] == 'v') { int j = B[mark1].number; for(int i = 0; i < B[mark3].number - mark4; i++) { B[mark1].B[j+i] = B[mark3].B[mark4 + i]; } B[mark1].number = j + B[mark3].number - mark4; B[mark3].number = mark4 ; } else { for(int i = mark2 + 1; i < B[mark1].number; i++) { B[B[mark1].B[i]].B[0] = B[mark1].B[i]; B[B[mark1].B[i]].number = 1; } B[mark1].number = mark2 + 1; for(int i = 0; i < B[mark3].number - mark4; i++) { B[mark1].B[mark2 + 1 + i] = B[mark3].B[mark4 + i]; } B[mark1].number = B[mark1].number + B[mark3].number - mark4; B[mark3].number = mark4 ; } }//else }//while for(int i = 0; i < test; i++) { printf("%d:", i); for(int j = 0; j < B[i].number; j++) { if(j != B[i].number) printf(" "); printf("%d", B[i].B[j]); } printf("\n"); } return 0; }
相关文章推荐
- uva 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- UVA101- The Blocks Problem
- UVA 101 The Blocks Problem【vector】
- uva 101 The Blocks Problem (基本算法-模拟)
- [UVA] 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- Uva 101 - The Blocks Problem
- Uva 101 The Blocks Problem(不定长数组 vector)
- UVA-101 The Blocks Problem 栈
- UVa-101 The Blocks Problem(栈模拟)
- uva 101 The Blocks Problem
- Problem 028——Uva 101 - The Blocks Problem
- Uva - 101 - The Blocks Problem
- UVa 101 - The Blocks Problem
- UVA - 101 The Blocks Problem(STL,模拟)
- UVa-101 - The Blocks Problem
- uva_101 - The Blocks Problem
- uva 101 The Blocks Problem (基本算法-模拟)
- UVa 101 (模拟) The Blocks Problem