DFS POJ 3087 Shuffle'm Up】的更多相关文章

题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ /************************************************ Author :Running_Time Created Time :2015-8-3 13:57:55 File Name :POJ_3087.cpp ***********************…
POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and…
POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到变换次数 变换规则如下: 假设s1=12345,s2=67890 变换后的序列 s=6172839405 如果s和s12完全相等那么输出变换次数 如果不完全相等,s的前半部分作为s1,后半部分作为s2,重复上述过程. 直接模拟,注意给出的顺序是从底到上的. 代码总览 #include <cstdio…
Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3087 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by s…
link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以把下面的一半作为S1,上面的一半作为S2,问能否洗出题目给出的最终字串. 思路:很好能够找到规律,就是先把两串合并,分别存a[i],a[i+n/2]到新串中,这个新串就是当前洗出的结果.因此进行DFS,由于给出的串长为偶数(?)所以必定能够洗回初始状态,所以出口就是初始串. /** @Date :…
http://poj.org/problem?id=3087 设:s1={A1,A2,A3,...Ac} s2={Ac+1,Ac+2,Ac+3,....A2c} 则 合在一起成为 Ac+1,A1,Ac+2,A2......A2c,Ac 经过一次转换之后变成 s1={Ac+1,A1,Ac+2.....} s2={...A2c,Ac} 对应之前,每个数的序号发生的变化是 +1,+2,+3....-c,-c+1,..... 把整个数链想成环,也相当于是: +1,+2,+3....+c,+c+1,...…
题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去. 现在输入s1和s2的初始状态 以及 预想的最终状态s12 问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1". #include <iostream> #include<cstdio> #…
题目链接:Shuffle'm Up 除了英文题有点恶心.发现模拟 + bfs 就可以过的时候,就是水了. 一个bug 就是filp函数得到string s12失败了.恩.据大腿告知,string 并不指定字符串的初始化长度是0,也就是说我每个元素的赋值是没有意义的.或者.string 是引用型数据类型,所以名字是一个指针吧.然后str.resize()函数愉快的解决了这个问题. 还有就是对题意.字符串从左到右是从下到上.我是懵了一下的. 题意思路见代码吧. /* 题目很长.也没有看.百度到题意.…
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去. 现在输入s1和s2的初始状态 以及 预想的最终状态s12.问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出"-1". 解题思路:照着模拟就好了,只是判断是否永远不能达到状态s12需要用map,定义map<…
Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10003   Accepted: 4631 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks o…
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several…
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several…
Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7404   Accepted: 3421 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of…
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each stack may contain chips of several…
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14471 Accepted: 6633 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of po…
题意:给定s1,s1两副扑克,顺序从下到上.依次将s2,s1的扑克一张一张混合.例如s1,ABC; s2,DEF. 则第一次混合后为DAEBFC. 然后令前半段为s1, 后半段为s2. 如果可以变换成所给出的字符串,输出变换次数即可:否则,输出-1. 这题数据太水了,我是这样判断无法变换成题目所给出的字符串的:将每一次变换后的字符串存进数组,每次变换后由于之前变换后的字符串相比较,如果有相同的,就说明会无限循环下去.这样一来,循环次数会增加很多,然而0ms过了... #include <iost…
直达–>POJ 3087 Shuffle'm Up 题意:一开始没怎么看明白,注意现是从S2里拿牌放在最底下,再放S1,这样交叉放(我一开始以为是S1和S2随意哪个先放,分别模拟取最小),然后在从中间截一半,下半部给组成新的S1,上半部组成新的S2.然后再交叉洗牌,重复,问达到给出的S12最小的洗牌次数. 思路:题意懂了直接模拟就行,无法到达的情况就是某一次洗牌出来的S12和之前出现过的S12重合了,也就是形成了循环,此时无法达到给出的S12的情况那就是不可能了.判重没想到什么特别巧妙的方法就用…
Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15249   Accepted: 6962 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks o…
Shuffle'm Up 直接写中文了 Descriptions: 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到变换次数 变换规则如下: 假设s1=12345,s2=67890 变换后的序列 s=6172839405 如果s和s12完全相等那么输出变换次数 如果不完全相等,s的前半部分作为s1,后半部分作为s2,重复上述过程. Input 第一行给出T(1≤T≤1000),代表有T组数据,每组数据首先给出…
Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7364   Accepted: 3408 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of…
题意:(1)有两副颜色多样的扑克牌,(A~H)表示不同颜色,给你两副牌,S1,S2和一副你需要洗出的KEY,S12由S2最底部,S1底部...一直下去,直到洗成S12,就是图片展示的那样.(2)洗好的S12可以重新变成新的S1,S2,S1是从下取S12牌数的一半,S2的从上取S12牌数的一半,问:这样操作有限次,能不能洗出S3,可以的话,求出最少洗牌次数,不能的话输出-1. 思路:算一个水题吧,简单的模拟,就是按照洗牌,拆牌那样模拟就好了,为了确定这个KEY能不能洗出, 需要一个map<stri…
题目链接:http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of poker chips, S1 and S2, each stack containing C chips. Each…
POJ 3411 Paid Roads Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6553   Accepted: 2430 Description A network of m roads connects N cities (numbered from 1 to N). There may be more than one road connecting one city with another. Some o…
题目传送门 /* DFS:问能否用小棍子组成一个正方形 剪枝有3:长的不灵活,先考虑:若根本构不成正方形,直接no:若第一根比边长长,no 这题是POJ_1011的精简版:) */ #include <cstdio> #include <iostream> #include <cstring> #include <map> #include <set> #include <cmath> #include <algorithm&g…
题目链接: http://poj.org/problem?id=2762 Going from u to v or from v to u? Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 14546   Accepted: 3837 Description In order to make their sons brave, Jiajia and Wind take them to a big cave. The cav…
题目传送门 /* DFS:因为一行或一列都只放一个,可以枚举从哪一行开始放,DFS放棋子,同一列只能有一个 */ #include <cstdio> #include <algorithm> #include <cstring> using namespace std; ][]; ]; int n, k, ans; void DFS(int x, int num) { ; i<=n; ++i) { if (maze[x][i] == '#' &&…
对于深度优先算法,第一个直观的想法是只要是要求输出最短情况的详细步骤的题目基本上都要使用深度优先来解决.比较常见的题目类型比如寻路等,可以结合相关的经典算法进行分析. 常用步骤: 第一道题目:Dungeon Master  http://poj.org/problem?id=2251 Input The input consists of a number of dungeons. Each dungeon description starts with a line containing th…
题目传送门 题意:数独问题,每行每列以及每块都有1~9的数字 分析:一个一个遍历会很慢.先将0的位子用vector存起来,然后用rflag[i][num] = 1 / 0表示在第i行数字num是否出现过,其他的类似,这样在用DFS就很快了,数据问题,反着搜索会更快... /************************************************ * Author :Running_Time * Created Time :2015/11/10 星期二 15:43:47 *…
模拟洗牌的过程,合并两堆拍的方式:使先取s2,再取s1:分离成两堆的方式:下面C张放到s1,上面C张到s2.当前牌型与第一次相同时,说明不能搜索到答案. AC代码 #include<cstdio> #include<cstring> const int maxn = 100 + 5; char s1[maxn], s2[maxn], s3[maxn * 2], s4[maxn * 2], vis[maxn * 2]; int c; void deal(char *a){ int c…
给一个矩形棋盘,每次走日字,问能否不重复的走完棋盘的每个点,并将路径按字典序输出 *解法:按字典序输出路径,因此方向向量的数组按字典序写顺序,dfs+回溯,注意flag退出递归的判断,并且用pre记录路径 #include <iostream> #include <cstdio> #include <cstring> using namespace std; char a[30][30]; int dx[] = {-2, -2, -1, -1, 1, 1, 2, 2};…