(简单) POJ 3087 Shuffle'm Up,枚举。
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,枚举。的更多相关文章
- POJ 3087 Shuffle'm Up(洗牌)
POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS Memory Limit: 65536K Description - 题目描述 A common pas ...
- POJ.3087 Shuffle'm Up (模拟)
POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到 ...
- DFS POJ 3087 Shuffle'm Up
题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ ...
- POJ 3087 Shuffle'm Up
Shuffle'm Up Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- 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 ...
- poj 3087 Shuffle'm Up ( map 模拟 )
题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...
- POJ 3087 Shuffle'm Up (模拟+map)
题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...
- POJ 3087 Shuffle'm Up DFS
link:http://poj.org/problem?id=3087 题意:给你两串字串(必定偶数长),按照扑克牌那样的洗法(每次从S2堆底中拿第一张,再从S1堆底拿一张放在上面),洗好后的一堆可以 ...
- [暴力搜索] POJ 3087 Shuffle'm Up
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10003 Accepted: 4631 Des ...
随机推荐
- String.valueOf(int i)和Integer.toString(int i)有什么区别?
以下是2个人的回答,我是从百度上复制下来的,做个笔记,以后方便看 String.valueOf()它可以将JAVA基本类型(int,double,boolean等)和对象(Object)转换成Stri ...
- 最简单易懂的webService客户端之soap+xml请求
代码准备: 1.网络上有提供一些免费的服务器测试地址,可以上这里找一找:https://my.oschina.net/CraneHe/blog/183471 2.我选择了一个翻译地址:http://w ...
- Power oj2470/DFS
题目链接 2469: C 小Y的难题(1) Time Limit: 1000 MS Memory Limit: 65536 KB Total Submit: 9 Accepted: 7 Page Vi ...
- liunx 平台下软件包管理
RPM/DPKG 两大阵营简介 在 GNU/Linux( 以下简称 Linux) 操作系统中,RPM 和 DPKG 为最常见的两类软件包管理工具,他们分别应用于基于 RPM 软件包的 Linux 发行 ...
- 使用Github搭建个人博客网站
1 新建一个repo,创建一个没有父节点的分支gh-pages(github规定,只有该分支中的页面,才会生成网页文件): mkdir jekyll_demo cd jekyll_demo git i ...
- 转:SQL Case when 的使用方法
Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END ...
- android xml文件中出现如下提醒:This tag and its children can be replaced by one <TextView/> and a compound drawable
第一个感叹号 是跟你说 让你把Imageview 和textview 结合起来 只用 textview textview有个属性叫 android:drawable...(top/bottom/.. ...
- HDU 2672 god is a girl
先找规律,发现是斐波那契数列...然后..水题.. #include<cstdio> #include<cstring> #include<cmath> #incl ...
- redis 工具类 单个redis、JedisPool 及多个redis、shardedJedisPool与spring的集成配置
http://www.cnblogs.com/edisonfeng/p/3571870.html http://javacrazyer.iteye.com/blog/1840161 http://ww ...
- iptables原理详解以及功能说明
原文:http://www.svipc.com/thread-450-1-1.html 前言 iptables其实就是Linux下的一个开源的信息过滤程序,包括地址转换和信息重定向等功能的,他由四 ...