POJ 3087 Shuffle'm Up(模拟)

Unity零基础到入门 ☀️| 基础知识入门篇章,看完就可以做游戏啦! | 寻找C站宝藏 Unity入门基础知识。本篇文章介绍了关于Unity入门的一些基础知识,包括基本概念和使用实例。简单易上手,轻松实现Unity入门操作! 阅读详情

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;
}








编译zlib库给IOS平台用 在弹出的下面对话框中选择Unix Makefiles ,然后点击(Done)完成。使用 lipo与otool查看库类型为arm64,现在可在ios平台使用该库了。zlib自带CMakeLists.txt 所以用CMake-GUI来生成。修改为与系统当前安装的cmake版本 (如:3.22.1)选择zlib源码目录及输出目录,输入下图的CMAKE参数。点击Configure,在弹出的对话框中选择Yes。cmake --install . 进行安装。cmake --build . 进行编译。 阅读详情

相关推荐

基于多智能体协作的量化交易研究框架TradingAgents详解

量化交易系统通过算法模型分析市场数据,旨在实现自动化投资决策。其核心原理在于利用计算机强大的数据处理能力,结合统计学和机器学习方法,从历史数据中挖掘可重复的盈利模式。这一技术的价值在于能够克服人类情绪干扰,实现纪律性交易,并快速处理海量信息。在应用场景上,量化策略广泛应用于股票、期货、外汇等多个金融市场。本文聚焦的TradingAgents框架,创新性地引入了**多智能体协作**和**对抗性验证**机制,通过模拟真实投研团队的分工与辩论流程,构建了一个研究友好、决策过程可解释的量化交易研究平台,为探索大语言

weixin_36019375的博客 431

[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

保姆级教程:在Ubuntu 22.04上用Python3.10和pysoem搞定EtherCAT电机回零与位置控制

本文提供在Ubuntu 22.04上使用Python3.10和pysoem实现EtherCAT电机回零与位置控制的详细指南。涵盖环境搭建、权限配置、EtherCAT主站架构解析、CiA402协议核心机制及工业级精度控制实现,帮助开发者快速掌握Python在工业自动化中的应用。

weixin_30952535的博客 329

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

故障处理:Oracle一体机磁盘故障时磁盘组重平衡失败的故障处理

摘要: Oracle Exadata一体机出现磁盘故障案例,存储节点故障灯未亮但磁盘已产生大量坏块,导致重平衡失败。文章强调了一体机硬件巡检需检查6个关键维度:节点messages日志、存储cell告警日志、CellCLI日志、ASM告警日志、ILOM日志及服务器信号灯。故障分析显示硬盘物理故障导致磁盘组冗余受损,自动修复流程受阻。文中详细记录了通过CellCLI工具排查损坏磁盘的过程,并提供了完整的故障处理流程和命令输出。文章同步发布于微信公众号"IT民工的龙马人生"和博客网站(www

提供数据库技术支持(系统优化,故障处理,安装升级,数据恢复等) 1231

Arduino安装图文教程:小白也能轻松上手

手把手带你完成Arduino安装全过程,无论你是编程新手还是硬件小白,都能快速搭建开发环境。结合arduino安装教程与实操步骤,避开常见错误,让创作即刻启程。

weixin_35509395的博客 1107

解题报告——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

fastlio2原理详解

其核心是利用IMU的高频数据(通常100-500Hz)进行状态预测(前向传播),同时利用激光雷达扫描(通常10-100Hz)作为观测来校正状态。转换了卡尔曼增益的计算公式,将对大维度观测矩阵的求逆(点云数量级)转换为对小维度状态矩阵的求逆,从而极大提升了计算效率。:利用预测出的连续IMU状态,将一帧内每个激光点根据其时间戳反向插值,统一校正到扫描结束时刻,输出无畸变的点云。收敛后,用最终的状态将本帧点云。,根据其精确的时间戳,利用前后两个IMU位姿进行插值,计算出该点采集时刻的精确位姿,再将其全部。

Studying…… 102

POJ - 3087 (Shuffle'm Up)

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

Joker & Liar的博客 231

【YOLOv8改进[Conv]】使用OREPA助力V8更优秀

使用OREPA助力V8更优秀,降低训练成本,在不引入任何推理时间成本的情况下提高深度模型的性能。

静谧、淡雅 1917

【开源电机驱动】位置环控制

这是三闭环里的最后一个:位置闭环控制。如果你认真的阅读并推导了前章节,那么这一节将会很好理解。一如既往,我会使用简练的语言来描述复杂的问题。本章节主要涉及位置环的一些概念,以及控制框图。文章不会涉及具体的代码。

BadBoyHolly的博客 6095

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

GEE初学:谷歌地球引擎GEE入门指南(最新注册全流程)

本教程详细介绍了谷歌地球引擎(GEE)的注册与基础操作流程。主要内容包括:1)非商业账号注册步骤,需提供学术机构凭证和研究目的;2)Google Cloud项目创建与API激活;3)Shapefile文件上传方法及资源ID获取;4)JavaScript脚本编写与地图可视化实现。教程通过代码示例展示了两种多边形显示方式(填充和轮廓模式),并强调了GEE的云端处理优势,包括免费访问40多年卫星数据、无需本地高性能硬件等特点。整个流程从账号注册到首个地图可视化完成约需10-15分钟,适合遥感分析初学者快速入门。

此星光明博客 2141

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

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

【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

VC中sqlite的使用

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

【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

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

【题解】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、付费专栏及课程。

余额充值