Uva-227 - Puzzle-AC
来源:互联网 发布:中国校园霸凌数据 编辑:程序博客网 时间:2024/05/02 06:13
解体思路:二维数组储存原型,记录空格位置,按顺序移动,移动越界即为This puzzle has no final configuration.
注意:1、这个题输出格式卡的我老是WA,注意具体那个空行的位置
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
Puzzle #1:
T R G S J
X O K L I
M D V B N
W P A E
U Q H C F
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAA
LLLL0
Puzzle #2:
A B C D
F G H I E
K L M N J
P Q R S O
T U V W X
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAAAABBRRRLL0
Puzzle #3:
This puzzle has no final configuration.
Z
Process returned 0 (0x0) execution time : 16.359 s
Press any key to continue.
2、这个题读取原型时,也应注意不要用scanf,因为有空格!
AC代码:
#include <stdio.h>#include <stdlib.h>int main(){ int i,j,x,y,t=1,flag; char a[10][10]; while(1) { flag=0; for (i=0;i<5;i++) { for (j=0;j<5;j++) { a[i][j]=getchar(); if (a[0][0]=='Z') return 0; if (a[i][j]==' ') {x=i; y=j;} } getchar(); } char commd; while((commd=getchar())&&commd!='0') { if (flag) continue; if (commd=='A') { if (x==0) {flag=1;continue;} a[x][y]=a[x-1][y]; a[x-1][y]=' '; x--; } else if (commd=='B') { if (x==4) {flag=1;continue;} a[x][y]=a[x+1][y]; a[x+1][y]=' '; x++; } else if (commd=='L') { if (y==0) {flag=1;continue;} a[x][y]=a[x][y-1]; a[x][y-1]=' '; y--; } else if (commd=='R') { if (y==4) {flag=1;continue;} a[x][y]=a[x][y+1]; a[x][y+1]=' '; y++; } } if (t-1) putchar('\n'); printf("Puzzle #%d:\n",t++); if (!flag) { for (i=0;i<5;i++) { for (j=0;j<5;j++) { if (!j) printf("%c",a[i][j]); else printf(" %c",a[i][j]); } putchar('\n'); } } else printf("This puzzle has no final configuration.\n"); getchar(); } return 0;}
0 0
- Uva-227 - Puzzle-AC
- UVa 227 Puzzle AC
- uva 1399 - Puzzle(AC自动机)
- UVA 1399 - Puzzle(AC自动机+DP)
- UVa 227 - Puzzle
- UVa 227 - Puzzle
- Uva-227-Puzzle
- UVa 227 Puzzle
- UVA - 227 Puzzle
- UVa 227 - Puzzle
- UVa-227 - Puzzle
- 【Uva 227】 Puzzle
- UVa 227 - Puzzle
- UVa 227 Puzzle
- UVA - 227 Puzzle
- Uva - 227 - Puzzle
- UVA - 227 Puzzle
- UVa 227 Puzzle
- sitemesh3.0的配置以及在静态html中的使用
- this must be done
- android ListView 单条刷新方法实践及原理解析
- 触发器二(DML触发器)
- poj 1018 Communication System
- Uva-227 - Puzzle-AC
- cocos2dx3.2 读取json
- iOS动画进阶(十三)高效绘图
- WinForm 清空界面控件值的小技巧
- 基于Apache Mina实现的TCP长连接和短连接实例
- nginx 配置说明
- 多线程同步I/O和单线程异步I/O
- 触发器三(行级DML触发器)
- 行列转换