(简单) 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 ...
随机推荐
- 【搜索 回溯】 zoj 1002
题意:一些机枪彼此不能在同一行和同一列,但是由于有墙的阻隔,能保证子弹无法穿透,即可以同行同列,现问如果说给了一个n*n(n<=4)的矩阵,并给出了墙的分布情况,能否求出最大能繁殖的机枪数. 思 ...
- Spring Boot 系列教程12-EasyPoi导出Excel下载
Java操作excel框架 Java Excel俗称jxl,可以读取Excel文件的内容.创建新的Excel文件.更新已经存在的Excel文件,现在基本没有更新了 http://jxl.sourcef ...
- Hibernate 系列教程16-二级缓存
pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate- ...
- 源代码管理工具-GIT
源代码管理工具-GIT ---- 一. 掌握 - git 概述 1. git 简介? 什么是git? git是一款开源的分布式版本控制工具在世界上所有的分布式版本控制工具中,git是最快.最简单.最流 ...
- 编译hadoop2.4
摘自 http://www.aboutyun.com/thread-8130-1-1.html.http://www.dataguru.cn/forum.php?mod=viewthread& ...
- Android真机连接手机Target显示unknown cmd命令下adb devices 显示offline
主要原因是adb版本的问题: 1.找到adb.exe路径 比如:G:\BaiduYunDownload\Android\android-sdk\platform-tools,将该路径放到环境便利-- ...
- maven学习笔记 1
1 概述 1.1 Maven是什么 1.2 为什么要用Maven 2 怎么用Maven 2.1 Maven仓库 2.2 Maven安装 2.3 Eclipse插件 2.4 Maven常用命 ...
- L6,Percy Buttons
expressions: knock at敲打 knock off 碰掉,I knock the vase off the table 下班,He always knocks off six o'cl ...
- 编程实现prim算法和Dijkstra算法。
网址链接:http://blog.csdn.net/anialy/article/details/7603170
- VNC轻松连接远程Linux桌面
VNC连接Linux桌面,要想连接Linux远程桌面,按照下面的步骤,非常简单.快速,Linux配置VNC(以RedHat.CentOS.Fedora系列为例). 工具/原料 Linux平台安装VNC ...