摘要:
题意:有两个杯子 容量分别为 A,B;每次可以将其中一杯杯子倒满或倒空,或者将一个杯子中的水倒入另外一个杯子(必须将其中一个杯子倒空或倒满)。 这样每种状态就有可能衍生出六种新的状态。 典型的BFS。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 int n,m; 11 12 bool sta[110][110]; 13 14 struct Q 15 { 16 int n,m,step,mar... 阅读全文
posted @ 2013-08-21 16:40
好小孩
阅读(167)
评论(0)
推荐(0)
摘要:
赤裸裸的模拟题。。 给出字符串 s1,s2,s12;判断s1,s2能够通过题目中所给的规则到达 s12。每次只会产生一种新的状态,还BFS个毛线-- s1的首位新生成的字符串的首,s2的尾为新生成字符串的尾。中间的字符依次交叉排列。 再将新生成的字符串的前一半给s1,后一半给s2。 重复上述两步 直到到达 s12 或者 新生成的字符串已经出现过。 前者输出步数,后者输出 -1。 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 struct N1... 阅读全文
posted @ 2013-08-21 16:35
好小孩
阅读(167)
评论(0)
推荐(0)
浙公网安备 33010602011771号