题意: 3*3方格,有一个是空的.其他的每个格子里有一个立方体.立方体最初上下白色,前后红色,左右蓝色.移动的方式为滚.给出初态空的位置,终态上面颜色情况,问最少多少步能到达.如果超过30步不能到达,-1. 思路: 模拟. 另外再加了一个A*优化.就是估计一下.应该还能优化的.感觉像二进制上可以优化.实在不想写了. 代码: //16:50 #include <cstdio> #include <cstring> #include <queue> #include <…
题意: 对于一个n元组(a0,a1,...),一次变换后变成(|a0-a1|,|a1-a2|,...) 问1000次变换以内是否存在循环. 思路: 模拟,map判重 代码: #include <cstdio> #include <cstring> #include <map> #include <cmath> #include <algorithm> using namespace std; struct Node{ ]; int n; void…
题意: 格式化代码.每个单词对齐,至少隔开一个空格. 思路: 模拟.求出每个单词最大长度,然后按行输出. 代码: #include <cstdio> #include <cstdlib> #include <cstring> ][][]; ]; ]; typedef char * pchar; int readStr(pchar &str, char *out) { ; int ret = sscanf(str, "%s%n", out, &…
Let's play a puzzle using eight cubes placed on a 3 x 3 board leaving one empty square.Faces of cubes are painted with three colors. As a puzzle step, you can roll one of the cubes to the adjacentempty square. Your goal is to make the specified color…
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=380 做了这道题之后对BFS总算是有了点认识了. #include<iostream> #include<cstring> using namespace std; ][]; typedef struct node { int x, y, z; node(int a,…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1026 题目大意:就是说给你一个8数码,问你能够达到的距离最远的状态是什么. 刚开始以为只要顺着一边走就行了,后来发现这样走可能最远到达的状态也能通过其他方式到达. 在这里WA了好多次. 应该把所有可能出现的情况全都枚举出来,然后判重.. UVA也真是慢..4s的代码跑了快4分钟..…
题意:蚂蚁在木棍上爬,速度1cm/s,给出木棍长度和每只蚂蚁的位置,问蚂蚁全部下木棍的最长时间和最短时间. 模拟一下,发现其实灰常水的贪心... 不能直接求最大和最小的= =.只要求出每只蚂蚁都走长路下木棍时的最大值,和走短路时的就行了. 代码: /* * Author: illuz <iilluzen@gmail.com> * Blog: http://blog.csdn.net/hcbbt * File: uva10714.cpp * Lauguage: C/C++ * Create Da…
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #include <string> #include <queue> #include <vector> #include <i…
题目大意:立体的八数码问题,一次操作是滚动一次方块,问从初始状态到目标状态的最少滚动次数. 题目分析:这道题已知初始状态和目标状态,且又状态数目庞大,适宜用双向BFS.每个小方块有6种状态,整个大方格有9*6^8个状态.每个小方块用一位6进制数表示即可. 注意:状态转移时要谨慎,否则会出现意想不到的错误: 这道题的末状态有256(2^8)个,如果对搜索层数不加限制,即使双向BFS也会TLE的,当限制正向搜索15层逆向搜索15层至正向搜索27层反向搜索3层时都能AC(我下面贴出的程序是这样的),其…
A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there…