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 different colors.

  The actual shuffle operation is performed by interleaving a chip from S1 with a chip from S2 as shown below for C = 5:

  The single resultant stack, S12, contains 2 * C chips. The bottommost chip of S12 is the bottommost chip from S2. On top of that chip, is the bottommost chip from S1. The interleaving process continues taking the 2nd chip from the bottom of S2 and placing that on S12, followed by the 2nd chip from the bottom of S1 and so on until the topmost chip from S1 is placed on top of S12.

  After the shuffle operation, S12 is split into 2 new stacks by taking the bottommost C chips from S12 to form a new S1 and the topmost C chips from S12 to form a new S2. The shuffle operation may then be repeated to form a new S12.

  For this problem, you will write a program to determine if a particular resultant stack S12 can be formed by shuffling two stacks some number of times.

  题目就是洗牌了,按照他的规则来洗,这个过程可以直接模拟,可以发现编号小于等于C(从下往上编号。)就乘以2,大于C的就乘以2然后-1,然后取模,这样的话可以看出洗牌会循环,因为只有2C种编号,对于某个来说第2C+1次一定是之前有过的编号,每一个都会循环的话,那这整个一定也会循环吧,我觉的就是周期为2C。

  然后就是一次次洗牌就好了,出现循环的话就算是不可能了。

代码如下:

#include<iostream>
#include<cstring> using namespace std; char End[];
char Sta[];
int Snum[];
int C; void change()
{
for(int i=;i<=*C;++i)
if(Snum[i]<=C)
Snum[i]*=;
else
Snum[i]=(Snum[i]-C)*-;
} bool judge()
{
for(int i=;i<=C*;++i)
if(End[Snum[i]-]!=Sta[i-])
return ; return ;
} void slove()
{
for(int i=;i<=*C;++i)
Snum[i]=i; int ans=; change(); while(Snum[]!=)
{
if(judge())
{
cout<<ans<<endl;
return;
} change();
++ans;
} if(judge())
cout<<ans<<endl;
else
cout<<-<<endl;
} int main()
{
ios::sync_with_stdio(false); int T;
char temp[];
cin>>T; for(int cas=;cas<=T;++cas)
{
cin>>C;
cin>>Sta;
cin>>temp;
strcat(Sta,temp);
cin>>End; cout<<cas<<' ';
slove();
} return ;
}

(简单) POJ 3087 Shuffle'm Up,枚举。的更多相关文章

  1. POJ 3087 Shuffle'm Up(洗牌)

    POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 A common pas ...

  2. POJ.3087 Shuffle'm Up (模拟)

    POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到 ...

  3. DFS POJ 3087 Shuffle'm Up

    题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ ...

  4. POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  5. POJ 3087 Shuffle'm Up 线性同余,暴力 难度:2

    http://poj.org/problem?id=3087 设:s1={A1,A2,A3,...Ac} s2={Ac+1,Ac+2,Ac+3,....A2c} 则 合在一起成为 Ac+1,A1,Ac ...

  6. poj 3087 Shuffle'm Up ( map 模拟 )

    题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...

  7. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  8. POJ 3087 Shuffle'm Up DFS

    link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以 ...

  9. [暴力搜索] POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10003   Accepted: 4631 Des ...

随机推荐

  1. 自定义switch开关

    自定义一个switch开关 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  2. OpenLayers 3 的地图基本操作

    <body> <div id="map"> <div id="menu"> <button id="zoom ...

  3. 。net MVC 序列化 反序列化

           序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写入到临时或持久性存储区.以后,可以通过从存储区中读取或反序列化对象 ...

  4. 添加一个Application Framework Service

    如何添加一个Application Framework Service(without native code)? 1.本文参照AlarmManagerService实现一个简单的Applicatio ...

  5. js框架——angular.js(5)

    1. 3种过滤方式 <html> <head> <meta charset='utf-8'> <script src="js/angular.js& ...

  6. javascript语句语义大全(6)

    var d = new Date();//创建当前日期对象var d = new Date('2016/03/22');//允许var d = new Date('2016/3/22');//允许va ...

  7. 学习笔记——桥接模式Bridge

    桥接模式的目的是在设计初,就将实现与接口分离,在以后实现发生变化时,只需要改变传递的实现对象,在保持接口一致的情况,达到实现的变更. 在OperationInterface中就调用实现的方法imp.O ...

  8. Mysql limit性能优化(小offset与大offset)

    MySQL的优化是非常重要的.其他最常用也最需要优化的就是limit.MySQL的limit给分页带来了极大的方便,但数据量一大的时候,limit的性能就急剧下降.   同样是取10条数据 selec ...

  9. PAT (Advanced Level) 1102. Invert a Binary Tree (25)

    简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...

  10. Centos-ip配置详解

    1 搭建好Centos ,我这里是CentOS-6.7-x86_64-minimal  提供一个下载地址 链接:http://pan.baidu.com/s/1nvTUTh3 密码:xewk 2 我是 ...