Puzzle, ACM/ICPC World Finals 1993, UVa227

有一个5*5的网格,其中恰好有一个格子是空的,其他格子各有一个字母。一共有4种指
令:A, B, L, R,分别表示把空格上、下、左、右的相邻字母移到空格中。输入初始网格和指
令序列(以数字0结束),输出指令执行完毕后的网格。如果有非法指令,应输出“This
puzzle has no final configuration.”,例如,图3-5中执行ARRBBL0后,效果如图3-6所示。

写的比较简陋,先写了容器,然后填充,写移动条件。

以下是用C写的源码:

#include<stdio.h>
#include<string.h>
int main()
{
char net[7][7],c=65,ch;int i,j;
memset(net,32,sizeof net);
for(i=1;i<6;i++)
for(j=1;j<6;j++)
net[i][j]=(c++);
net[5][5]=42;
int x=5,y=5,temp;
do{
while((c=getchar())!=EOF&&(c==65||c==66||c==76||c==82))
{
if(x>0&&x<7&&y<7&&y-1>0&&c==65)
{temp=net[y][x];net[y][x]=net[y-1][x];net[y-1][x]=temp;y--;}
if(x>0&&x<7&&y>0&&y+1<7&&c==66)
{temp=net[y][x];net[y][x]=net[y+1][x];net[y+1][x]=temp;y++;}
if(x-1>0&&x<7&&y>0&&y<7&&c==76)
{temp=net[y][x];net[y][x]=net[y][x-1];net[y][x-1]=temp;x--;}
if(x>0&&x+1<7&&y>0&&y<7&&c==82)
{temp=net[y][x];net[y][x]=net[y][x+1];net[y][x+1]=temp;x++;}
}
if(c!=65&&c!=66&&c!=76&&c!=82)
printf("The puzzle has no final configuration.\n");
for(i=0;i<7;i++) {for(j=0;j<7;j++) printf("%c",net[i][j]);printf("\n");}
}while(c!=‘q‘);
return 0;
}
~                                                                                  
~                                                                                  
~
时间: 2024-08-03 05:40:48

Puzzle, ACM/ICPC World Finals 1993, UVa227的相关文章

[算法竞赛入门经典] Crossword Answers ACM/ICPC World Finals 1994,UVa232

Description A crossword puzzle consists of a rectangular grid of black and white squares and two lists of definitions (or descriptions). One list of definitions is for "words" to be written left to right across white squares in the rows and the

[UVa 213]Message Decoding,ACM/ICPC World Finals 1991 信息解码

A children's board game consists of a square array of dots that contains lines connecting some of the pairs of adjacent dots. One part of the game requires that the players count the number of squares of certain sizes that are formed by these lines.

[算法竞赛入门经典]Message Decoding,ACM/ICPC World Finals 1991,UVa213

Description Some message encoding schemes require that an encoded message be sent in two parts. The first part, called the header, contains the characters of the message. The second part contains a pattern that represents the message. You must write

信息解码,ACM/ICPC World Finals 1991

问题 考虑下面的01串序列: 0, 00, 01, 10, 00, 001, 010, 011, 100, 101, 110, 0000, 0001, --, 1101, 1110, 00000, -- 首先是长度为1的串,然后是长度为2的串,依次推类.如果看成二进制,相同长度的后一个串等于前一个串加1.上述序列中不存在全为1的串: 编写一个解码程序.首先输入一个编码头(例如 AB#TANCnrtXc), 则上述序列的每个串依次对应编码头的每个字符.例如0对应A,00对应B,01对应#,--:

hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup

http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Alice was felling into a cave. She found a strange door with a number square m

2016 ACM/ICPC Asia Regional Shenyang Online 1009/HDU 5900 区间dp

QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 859    Accepted Submission(s): 325 Problem Description Every school has some legends, Northeastern University is the same. Enter

《ACM/ICPC 算法训练教程》读书笔记一之数据结构(堆)

书籍简评:<ACM/ICPC 算法训练教程>这本书是余立功主编的,代码来自南京理工大学ACM集训队代码库,所以小编看过之后发现确实很实用,适合集训的时候刷题啊~~,当时是听了集训队final的意见买的,感觉还是不错滴. 相对于其他ACM书籍来说,当然如书名所言,这是一本算法训练书,有着大量的算法实战题目和代码,尽管小编还是发现了些许错误= =,有部分注释的语序习惯也有点不太合我的胃口.实战题目较多是比较水的题,但也正因此才能帮助不少新手入门,个人认为还是一本不错的算法书,当然自学还是需要下不少

2014 ACM/ICPC Asia Regional Guangzhou Online Wang Xifeng&#39;s Little Plot HDU5024

一道好枚举+模拟题目.转换思维视角 这道题是我做的,规模不大N<=100,以为正常DFS搜索,于是傻乎乎的写了起来.各种条件限制模拟过程 但仔细一分析发现对每个点进行全部八个方向的遍历100X100X100^8 .100X100个点,每个点在走的时候8中选择,TLE 于是改为另一个角度: 以符合要求的点为拐弯点,朝两个垂直的方向走,求出最远的距离.这样只要对每个点各个方向的长度知道,组合一下对应的就OK. 避免了每个点深搜. PS:搜索的时候x,y写反了,导致构图出现问题,以后用[dy][dx]

HDU 5014 Number Sequence(2014 ACM/ICPC Asia Regional Xi&#39;an Online) 题解

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5014 Number Sequence Problem Description There is a special number sequence which has n+1 integers. For each number in sequence, we have two rules: ● ai ∈ [0,n] ● ai ≠ aj( i ≠ j ) For sequence a and sequ