POJ 3087 Shuffle'm Up(模拟)

CodeBlocks如何将英文环境改为中文 一、下载汉化包(链接如下) 链接:https://pan.baidu.com/s/166U9WGPbJXu2hyD7q9EiJQ 提取码:2333 二、选择路径 将汉化包中的文件(CodeBlocks.mo、zh_CN.mo、zh_CN.po)放到CodeBlocks安装路径下的​​​​​​CodeBlocks/share/CodeBlocks/locale/zh_CN文件夹中,路径中的文件夹没有就新建。 注:此处需严格按照要求来,切勿自定义文件夹名 三、内部调试 打开CodeBlocks,.. 阅读详情

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.

Input

The first line of input contains a single integer N, (1 ≤ N ≤ 1000) which is the number of datasets that follow.

Each dataset consists of four lines of input. The first line of a dataset specifies an integer C, (1 ≤ C ≤ 100) which is the number of chips in each initial stack (S1 and S2). The second line of each dataset specifies the colors of each of the C chips in stack S1, starting with the bottommost chip. The third line of each dataset specifies the colors of each of the C chips in stack S2 starting with the bottommost chip. Colors are expressed as a single uppercase letter (A through H). There are no blanks or separators between the chip colors. The fourth line of each dataset contains 2 * C uppercase letters (A through H), representing the colors of the desired result of the shuffling of S1 and S2 zero or more times. The bottommost chip’s color is specified first.

Output

Output for each dataset consists of a single line that displays the dataset number (1 though N), a space, and an integer value which is the minimum number of shuffle operations required to get the desired resultant stack. If the desired result can not be reached using the input for the dataset, display the value negative 1 (−1) for the number of shuffle operations.

Sample Input

2
4
AHAH
HAHA
HHAAAAHH
3
CDE
CDE
EEDDCC

Sample Output

1 2
2 -1

Source




题意: 给你a,b,c三堆牌,b放一张,a放一张,放成一堆新的牌,这样看能不能放成c,如果不能,那么底下的牌(数量已知)为a,上面为b,继续重复,

如果能放成功,输出次数,否则-1


模拟题,解释在代码



#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

string ss,e,s;
int ans,len;

void bfs()
{
    if(ans&&s==ss) //如果和第一次想同,不可能成功,死循环
        return ;

    if(s==e)  //放成功了
        return ;

    ++ans; //仿牌次数增加

    int i,j;
    string a,b;

    a=b="";
    for(i=0;i<len;i++)
        a+=s[i];   

    for(;i<len*2;i++)
        b+=s[i];

     s="";
    for(i=0;i<len;i++)
    {
        s+=b[i]; //先b
        s+=a[i];  //后a
    }

    bfs();
}

int main()
{
    int t,ca=0;
    int i,j;
    string a,b;

    scanf("%d",&t);
    while(t--)
    {
       cin>>len>>b>>a>>e; //不好意思,我是输入的b,a
       ans=0;
       s="";
       for(i=0;i<len;i++)  //这是第一次放牌,所以后面输出ans+1
       {
           s+=a[i];
           s+=b[i];
       }

        ss=s;
        bfs();

        if(s==e)
            printf("%d %d\n",++ca,ans+1);
        else
            printf("%d -1\n",++ca);
    }
    return 0;
}








人机协作新纪元:AI会抢走IT人的饭碗吗? 产品经理用自然语言描述需求,AI将其转化为技术规格书(准确率已达89%) 阅读详情

相关推荐

电力抄表协议DL/T645和698.45到底有啥区别?一张图帮你选对协议

本文深入对比了电力抄表协议DL/T645和DL/T698.45的技术差异,从协议架构、报文结构、功能覆盖到实施成本进行全面分析。通过实际案例和数据,揭示698.45协议在通信效率、业务扩展性和长期成本上的优势,并提供清晰的选型决策流程图,帮助工程师根据具体需求选择最适合的电力抄表协议。

weixin_38168696的博客 401

[kuangbin]专题一 简单搜索 Shuffle'm Up POJ - 3087【BFS】

【题目描述】 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 ch...

inv0ker的博客 256

描述符链表(Descriptor Chain)是什么?

描述符链表是硬件加速数据传输的核心数据结构,通过链式描述符(包含地址、长度、控制标志等)实现DMA自动批量处理,显著降低CPU负载。其工作原理为:CPU初始化链表后,硬件按序处理每个描述符,完成自动跳转与中断通知。在网卡收包、NVMe存储等场景中应用广泛,优势包括批处理、低延迟和灵活调度。需注意内存对齐、缓存一致性等实现细节,优化手段包括预分配描述符池、环形缓冲区等。该技术是网络/存储领域提升吞吐量的关键方案。

guigenyi的专栏 774

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,S1andS2, each stack co...

weixin_30558305的博客 249

基于Python大数据的智能交通分析系统

该系统能够实时监测交通状况,分析交通流量,预测交通趋势,为交通管理部门提供决策支持,帮助缓解交通拥堵,提高交通运行效率,减少交通事故发生率,改善市民出行体验。它能够为交通管理部门提供决策支持,帮助缓解交通拥堵,提高交通运行效率,减少交通事故发生率,改善市民出行体验,促进交通产业的健康发展。数据采集层:通过传感器、GPS设备、交通摄像头等数据源,实时采集交通数据,如车辆速度、位置、道路拥堵情况等。数据分析层:运用统计学方法、机器学习算法等,对处理后的数据进行深入分析,挖掘交通规律,预测交通趋势。

qq3828614760的博客 2969

3 种 VLA 模型动作表示方案对比:RT-2 离散化 vs π0 流匹配 vs HybridVLA 混合架构

本文深入对比了三种VLA模型动作表示方案:RT-2离散化、π0流匹配和HybridVLA混合架构。分析了各自的技术原理、优势与局限性,并提供了应用场景选择指南,帮助研究者在具身智能领域做出更优的技术选型决策。

weixin_29031161的博客 319

解题报告——poj3087

poj3087 题目链接: https://vjudge.net/problem/POJ-3087 题目类型:暴力模拟+字符串 字符串的题最好还是用string,比char数组方便很多 sacnf读入字符会读入回车,需要用getchar()消除 多个用例的情况下注意清空 提交记录 第一次CE,因为poj不支持c++11所以不能使用哈希表 第一次WA,加了一个清空字符数组e的语句 第二次WA,修改了第47行的memcpy,对于memcpy函数第三个参数是要复制过去的字节大小,要复制4个int就填4*si

smallEdward的博客 464

用户行为路径可视化_桑葚图(Sankey)

桑基图对用户行为路径可视化的blog学习笔记。

徐思孟的博客 3855

POJ - 3087 (Shuffle'm Up)

题意:首先设定一次转换,即图中 s1 和 s2 组成的 s12 ,下一轮 s12 的前半部分又成为了新的 s1,后半部分又成为了新的 s2; 现在给出 原始的 s1 和 s2 以及目标的 s12,问得经过多少轮转换之后,才可以 s1 和 s2 才可以组成目标的 s12,若永远不能则输出-1; 分析:暴力模拟转换过程就行了,用string操作会比较方便,然后用 set 记录中间达到过的...

Joker & Liar的博客 231

C#函数返回多个值实现实例

本文实例讲解C#函数返回多个值多种实现方法。

qq_30725967的博客 1170

LPDDR5 学习笔记08:电气参数设计要求

本文详细阐述了LPDDR5内存接口的关键电气规范和时序要求。主要内容包括:1)绝对最大额定值限制及长期工作可靠性说明;2)差分时钟信号(CK/WCK)的输入电压、转换速率和交叉点电压规范;3)单端时钟信号的定义和测量方法;4)时钟周期、抖动(周期抖动、相邻周期抖动)和累积误差的精确计算方法;5)片选信号在同步/异步模式下的接收器规范;6)命令地址信号和数据信号的接收器掩模定义及脉冲宽度要求。所有参数均严格定义了测量条件和合规标准,为LPDDR5接口设计提供了完整的电气规范参考。

一只豌豆象的博客 1176

Shuffle‘m Up(模拟>bfs)

Shuffle’m Up 题意:t组输入,先输入一个c表示长度,然后输入s1,s2长度都是c,然后再有一个2*c长度字符串,现在操作,两个短的字符串s2里先从头拿一个,然后s1交叉放置,合并后的字符串是否等于给出的长字符串,若不是的话,就是合成的前c个是新的s1,后c个是新的s2,反复操作,最少几步可以得到给定长字符串。 思路:bfs。然后就是跟题目描述一样的操作。 代码 #include<cstdio> #include<iostream> #include<cstring&

Celavia_yu的博客 291

am62x A53与R5F通信

AM62x是Ti的一款异构多核芯片。remoteproc驱动,硬编码(写死)了R5F/M4F固件的名字,这样驱动启动时,就会找硬件编码的固件,下面是其对应关系。值得注意的是,linux内核中的M4F remoteproc驱动启动M4F,而linux内核中的R5F remoreteproc驱动不启动R5F,相反,它attach到已经在boot阶段启动的R5F固件上。在/lib/firmware的真实固件名:,而我们生成的固件名如下所示,没有直接对应的,经确认,.out文件就是我们需要的,重命名后即可。

鹰之翔 1359

POJ.3087 Shuffle'm Up (模拟)

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,重复上述过程。直

Pengwill's Blog 266

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

【POJ 3087 --- Shuffle'm Up】模拟

【POJ 3087 --- Shuffle'm Up】模拟 题目来源:点击进入【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...

来日浅谈的博客 556

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

【Poj 3087 】 Shuffle'm Up 模拟

Shuffle’m Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8564 Accepted: 3932DescriptionA common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff

ATOD 1146

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

【题解】POJ - 3087 Shuffle'm Up 模拟

题目链接:http://poj.org/problem?id=3087 这是做kuangbin搜索专题遇到的,然后现在还是不会搜索,那就模拟吧 根据题目模拟,跳出循环的条件是s1数组出现了循环(证明永远不会得出s12) ac代码: #include<cstdio> #include<iostream> #include<cstring> using namesp...

替这位空想家惊讶 151

Shuffle'm Up POJ - 3087 模拟

一、内容 题意:给定2个字符串s1,s2,将2个字符串进行重组成S,规则是S2最下面拿一个,S1最下面拿1个,直到所有块都用完。 二、思路 用map记录下S串结果,若以前访问过这个串代表不可能有结果直接返回-1。 然后就是模拟重组串的过程。 三、代码 #include <cstdio> #include <iostream> #include <cstring&g...

Tizzi的博客 814

POJ3087 Shuffle'm Up 模拟

Shuffle’m Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16500 Accepted: 7502 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling ...

DouglasConnor的博客 303

poj 3087——Shuffle'm Up (模拟)

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,S1andS2, each stack containingCchips. Ea...

red_red_red的博客 161

POJ 3087 Shuffle'm Up(模拟)

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 shuf

叶孤心的专栏 1293

poj3087 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,S1andS2, each stack containin...

邵光亮的博客 648

poj 3087 Shuffle'm Up 模拟

Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7341   Accepted: 3396 Description A common pastime for poker players at a poker table is to sh

呼,是出一口气;吸,是争一口气! 523

poj3087 Shuffle'm Up 模拟

Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10039   Accepted: 4648 Description A common pastime for poker players at a poker table is to s

kyoma的博客 389

POJ 3087 Shuffle'm Up(模拟)

题意 给两堆牌s1,s2交给你洗 每堆有c张 每次洗牌得到s12 其中s2的最下面一张在s12的最下面一张然后按顺序一张s1一张s2 洗好之后可以把s12下面的c张做s1 上面的c张做s2 求多少次洗牌之后可以得到输入给你的串s 不能得到输出-1 简单模拟 s1+s2!=s就一直洗牌 如果回到初始状态都没得到s就不会得到s了 得到s就可以输出洗牌次数了

Good morning,good afternoon and good night 1135

POJ 3087 Shuffle'm Up(模拟+读题)

POJ 3087 http://poj.org/problem?id=3087 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...

夏日蹲坑的博客 291
上一篇: HDU 2614 Beat (dfs)
下一篇: HDU 1338 Game Prediction 贪心
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值