UVA 101 The Blocks Problem
来源:互联网 发布:北京少儿编程培训机构 编辑:程序博客网 时间:2024/05/18 01:08
UVA 101 The Blocks Problem
纯粹的模拟,,一开始题意理解错了 在POJ还过了,,换成UVA WA掉了 又改 才过的
#include <stdio.h>#include <string.h>int n;char a[10], b[10];int aa, bb;int stack[255][255];int num[255];int x, y;int x2, y2;void find(int xx){int i, j; for (i = 0; i < n; i ++)for (j = 0; j < n; j ++){if (stack[i][j] == xx){x = i; y = j;return;}}}void find2(int xx){int i, j; for (i = 0; i < n; i ++)for (j = 0; j < n; j ++){if (stack[i][j] == xx){x2 = i; y2 = j;return;}}}void move_onto(int a, int b){ find(a); find2(b);int i; for (i = num[x] - 1; i >= y + 1; i --) {stack[stack[x][i]][num[stack[x][i]]] = stack[x][i];num[stack[x][i]] ++;stack[x][i] = -1;num[x] --; }stack[x][y] = -1;num[x] --; for (i = num[x2] - 1; i >= y2 + 1; i --) {stack[stack[x2][i]][num[stack[x2][i]]] = stack[x2][i];num[stack[x2][i]] ++;stack[x2][i] = -1;num[x2] --; } stack[x2][y2 + 1] = a; num[x2] ++;}void pile_onto(int a, int b){ int sb; find(a); find2(b); int aa[30]; int t = 0; sb = num[x];int i; for (i = y; i < sb; i ++) {aa[t ++] = stack[x][i];stack[x][i] = -1;num[x] --; } for (i = num[x2] - 1; i > y2; i --) {stack[stack[x2][i]][num[stack[x2][i]]] = stack[x2][i];num[stack[x2][i]] ++;stack[x2][i] = -1;num[x2] --; } int tt = 0; for (i = y2 + 1; i < y2 + 1 + t; i ++) {stack[x2][i] = aa[tt++];num[x2] ++; }}void pile_over(int a, int b){ int sb; find(a); find2(b); int aa[30]; int t = 0; sb = num[x];int i; for (i = y; i < sb; i ++) {aa[t ++] = stack[x][i];stack[x][i] = -1;num[x] --; } int tt = 0; sb = num[x2]; for (i = sb; i < sb + t; i ++) {stack[x2][i] = aa[tt ++];num[x2] ++; }}void move_over(int a, int b){ find(a); find2(b);int i; for (i = num[x] - 1; i >= y + 1; i --) {stack[stack[x][i]][num[stack[x][i]]] = stack[x][i];num[stack[x][i]] ++;stack[x][i] = -1;num[x] --; } stack[x][y] = -1; num[x] --; stack[x2][num[x2]] = a; num[x2] ++;}int main(){ while (scanf("%d", &n) != EOF) {memset(stack, -1, sizeof(stack));memset(num, 0, sizeof(num));int i;int j;for (i = 0; i < n; i ++){stack[i][0] = i;num[i] ++;}getchar();while (scanf("%s",a) != EOF){int ju1 = 3;int ju2 = 3;if (strcmp(a, "quit") == 0){break;}scanf("%d %s %d", &aa, b, &bb);find(aa);find2(bb);if (x == x2 || aa == bb)continue;if (strcmp(a, "move") == 0){ju1 = 0;}if (strcmp(a, "pile") == 0){ju1 = 1;}if (strcmp(b, "onto") == 0){ju2 = 0;}if (strcmp(b, "over") == 0){ju2 = 1;}if (ju1 == 0 && ju2 == 0){move_onto(aa, bb);}if (ju1 == 0 && ju2 == 1){move_over(aa, bb);}if (ju1 == 1&& ju2 == 0){pile_onto(aa, bb);}if (ju1 == 1 && ju2 == 1){pile_over(aa, bb);}}for (i = 0 ; i < n; i ++){printf("%d:", i);for (j = 0; j < num[i]; j ++){if(stack[i][j] != -1)printf(" %d", stack[i][j]);}printf("\n");} } return 0;}
- 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
- 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
- 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
- UVa 101 The Blocks Problem
- UVa 101 - The Blocks Problem
- uva 101 The Blocks Problem
- Sobel滤波,Laplace滤波介绍与opencv实现
- 界面动态配置:持久化反持久化
- windows上python压缩zip包,包含空文件夹
- 第12周课程:箱型图,热力图
- windows 文件系统图标意外变化-----图标缓存
- UVA 101 The Blocks Problem
- Hive metastore三种存储方式
- HDU 1850 Being a Good Boy in Spring Festival
- 高精度bign
- 毕业后的五年拉开大家差距的原因
- UBI FAQ and HOWTO
- Android开发之WebService介绍
- UNIX环境高级编程——标准I/O库
- C++ 中内存分配和回收