POJ 3087 Shuffle'm Up(模拟)

工业场景落地:Java+PaddleOCR实现高性能OCR文字识别的终极方案 本文深度解析基于Java的高性能工业级OCR实现方案,集成PP-OCRv5深度学习模型,提供: ✅ 多场景支持:手写体、竖排文本、票据表格的精准识别 ✅ 工业级性能:毫秒级响应,支持GPU加速与高并发处理 ✅ 开箱即用:通过Maven快速集成,5行代码完成文字识别 ✅ 完整技术栈:覆盖文本检测、方向校正、识别后处理全流程 附可运行示例代码,助您快速构建企业级OCR系统! 阅读详情

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








【无人机路径规划】基于强化学习实现多无人机路径规划 阅读详情

相关推荐

双三相电机控制避坑指南:为什么你的SVPWM谐波大?四矢量调制实战解析

本文深入解析双三相电机控制中SVPWM谐波大的问题,并提供四矢量调制实战方案。通过分析谐波来源、四矢量调制原理及工程实现步骤,显著降低电流THD至3-5%,提升系统效率2.3个百分点。特别适合需要优化电机控制的工程师参考。

weixin_30645617的博客 397

[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

VS Code + Codex 在 WSL 中使用的正确姿势

Codex 登录只能在本地完成。文件仍可通过 UNC 路径访问 WSL → 本地 Codex 就能照常工作。避免在 WSL 内重复安装/登录 Codex 扩展。

yangguangwuyue的博客 9829

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

基于STM32F334C8T6的四开关Buck-Boost双向DC-DC电源设计与实现(附源码、仿真与计算书)

本文详细介绍了基于STM32F334C8T6的四开关Buck-Boost双向DC-DC电源设计方案。该设计利用STM32的高分辨率定时器(HRTIM)实现精确PWM控制,支持Buck、Boost和Buck-Boost三种工作模式自动切换,具备双向能量流动能力。通过PSIM仿真和Mathcad计算书进行参数优化,实测效率达95.8%,适用于新能源系统和电池管理等场景。

www00的博客 525

Python读取三菱PLC数据

3、支持自定义的数据读写操作。直接调用Read方法,可以读取到原生的byte数组,然后进行组合数据。1、每次的数据交互您都可以判断是否成功,如果您不判断,如果网络断开或是异常,会影响程序的执行。Qna3E协议的ascii类 MelsecMcAsciiNet。A兼容1E协议的二进制类 MelsecA1ENet。Qna3E协议的二进制类 MelsecMcNet。2、读写操作支持单个数和数组。

weixin_46744807的博客 1998

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

ComfyUI 的 LoRA 训练:素材打标签与调优全攻略

标签是 LoRA 训练的"地基"——地基打不牢,后续调参再精细也难出好效果。记住:标签要"少而精",聚焦独特点,用触发词控效果。下一篇我们将讲解参数设置,让你的优质标签发挥最大价值~

2301_78150483的博客 3099

POJ - 3087 (Shuffle'm Up)

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

Joker & Liar的博客 231

【文献笔记】ICCV 2021 | Point Transformer

作者提到,特别适合点云处理,因为自注意力机制是的核心,本质上就是一个集合算子:它对输入元素具有顺序不变性和数量不变性3D点云是无序的,即使改变点云txt文件中的点顺序也不会有任何影响。自注意力机制天然具有排列不变性,因为它通过对所有"点对"的关系进行建模来处理输入,而不依赖于任何特定的输入顺序点云数据通常覆盖了3D空间中的对象或场景,理解这些数据需要捕捉点与点之间复杂的空间关系。自注意力机制能够有效的捕捉这些关系,因为它为每个"点对"赋予一个。

m0_55908255的博客 965

【GlobalMapper精品教程】094:GlobalMapper26简体中文版安装教程(附安装包下载)

【GlobalMapper精品教程】094:GlobalMapper26简体中文版安装教程(附安装包下载)- 基于深度学习的图像分析工具,用于自动识别土地覆盖分类、建筑物提取和车辆检测。新的太阳阴影分析工具,用于计算加载地形和 3D 要素的阴影。新的 GENERATE_SHADOWS 脚本命令允许自动执行这些计算。新增点云模型关键点自动识别。能够在自动点云分析工具中保存和加载自定义创建的要素模型。改进了像素到点中各种潜在重叠图像中 GCP 的自动识别。

智慧空间实验室 4892

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

Camera2Demo

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

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

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

【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

【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

【题解】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

[模拟]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 contain

童凌的技术博客 496

POJ 3087 Shuffle'm Up 模拟

题意即给出两摞牌S1和S2,先从S2底部抽一张作为新的一摞S12的最后一张,再从S1底部抽一张放到S12上,重复以上步骤得到S12,再使S12的上半摞变为S2,下半摞为S1,问题是给出初始S1和S2,再给出一个S12,问S1和S2经过以上若干次操作后,能否合成S12。 用数组(string)模拟即可,不断重复题述步骤,若出现循环则会无限循环,则不可能再得到S12,判断方法用map就可以。 AC

EteYogix 311
上一篇: 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、付费专栏及课程。

余额充值