Shuffle'm Up POJ - 3087

基于FT2232集成USB直接实现XilinxJTAG和UART串口 使用“program_ftdi -write -ftdi FT2232H -serial 0ABC01 -vendor "my vendor co" -board "my board" -desc "my product desc"”命令进行数据烧写,该命令会将FT2232的通道A配置为JTAG,其余通道配置为UART,serial长度为6~12个字符(vivado扫描JTAG时显示的cable序列号,同一台PC能够同时连接多个不同序列号的cable仿真器)。图 2 program_ftdi的帮助信息。 阅读详情

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

题意:

给你两堆都为n块的堆,交叉得到一个新的堆。 然后将新堆再分成两堆,再合并,再分。。。。 一直到出现符合要求的堆,输出次数,若不可能输出-1.

分析:

肯定有循环节,模拟每次操作,当一个循环节结束时还没有找到就输出-1.



#include<iostream>
#include<cstdio>
#include<string.h>
#include<math.h>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
int main()
{
    int T;
    cin >> T;
    int k = 1;
    while(T--){
        cout << k << ' ';
        k++;
        int n;
        cin >> n;
        string a,b,c,last;
        cin >> a >> b >> last;
        for(int i=0;i<n;i++){
            c.push_back(b[i]);
            c.push_back(a[i]);
        }
        queue<string> q;
        q.push(c);
        int cnt = 1;
        while(!q.empty()){
            string temp = q.front();
            q.pop();
            if(temp == last){
                cout << cnt << endl;
                break;
            }

            a.assign(temp,0,n);
            b.assign(temp,n,n);
            string d;
            for(int i=0;i<n;i++){
                d.push_back(b[i]);
                d.push_back(a[i]);
            }
            if(d == c){
                cout << -1 << endl;
                break;
            }
            q.push(d);
            cnt++;
        }

    }
}



从零搭建 C# + YOLO 工业视觉系统:从模型训练到上位机部署(工业级落地) 做工业质检、自动化生产线的同学都懂:一套能用的工业视觉系统,既要“检测准”,又要“界面易操作”,还要“部署稳”。之前帮某电子厂做PCB缺陷检测,一开始用Python+YOLO做检测核心,QT做上位机,结果踩了无数坑:Python推理速度波动大,QT和Python跨语言集成繁琐,数据传递容易卡顿;后来换成C# + YOLO的组合,直接打通了“模型训练-上位机开发-工业部署”全流程——C#的WinForms/WPF开发上位机高效,工业相机SDK支持完善; 阅读详情

相关推荐

STM32+4G模块+MQTT协议:从零构建稳定可靠的物联网通讯链路

本文详细介绍了如何利用STM32、4G模块和MQTT协议构建稳定可靠的物联网通讯链路。通过硬件选型、AT指令配置和MQTT连接实战,帮助开发者实现低功耗、高可靠性的数据传输,特别适合户外和移动场景应用。

weixin_29191081的博客 334

[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

线性回归LinearRegression

对视频中线性回归算法的相关内容进行总结与记录 文章目录一、理论基础二、实例2.1 一元线性回归2.1.1 推导过程2.1.2 代码实现(基于numpy)2.1.3 代码实现(基于sklearn)2.2 多元线性回归2.2.1 代码实现(基于numpy)2.2.2 代码实现(基于sklearn) 一、理论基础 回归 通常是指利用某个函数,尽可能把数据样本点“串”在一起,用于描述输入变量和输出变量间的变化关系 线性回归 特点:用来把数据“串”起来的那个函数是线性的 (一元线性回归(一个自变量) &a.

邱邱邱的博客 1068

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

等保: Postgresql配置ssl链接

等保: postgresql配置ssl链接完整方案和避坑指南

weixin_43557605的博客 4381

【网络教程】Ubuntu有线连接消失,无法联网怎么办!(亲测有效!)

文章目录问题描述解决方案 问题描述 今天打开Ubuntu,突然发现无法连接网络,并且打开设置,发现设置里面的网络已经没有了有线连接,只有VPN设置选项,如图 解决方案 按照下列的代码执行即可! # 关闭网路 service NetworkManager stop # 删除NetworkManager缓存文件 sudo rm /var/lib/NetworkManager/NetworkManager.state # 打开网络 service NetworkManager start 运行完

XiaoqiangClub的博客 1万+

HDU 3430 Shuffling(中国剩余定理)

Shuffling Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 561Accepted Submission(s): 278 Problem Description A casino owns an expensiv...

~ 568

大模型长对话中上下文无法承载全部历史,如何压缩或提取重点

如果说截断和滑动窗口是“硬性”压缩,那摘要生成技术就显得“软”多了,也更接近于智能化的解决方案。它的思路是:不直接丢弃历史,而是通过自然语言处理(NLP)技术,把冗长的对话记录浓缩成一段简短的摘要,保留核心信息。这样既能大幅减少token数量,又不至于丢失关键内容。这种方法通常会借助预训练模型,比如BART或T5,它们擅长从长文本中提取重点内容。

大模型大数据攻城狮的专栏 1586

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

【知识分享】IBIS 建模指南 03

本文介绍了差分缓冲器的数据提取方法,重点分析了差分系统与单端系统的核心差异。文章详细阐述了差分接收机和驱动器的结构特点、工作原理及建模方法,指出全差分结构具有优异的电源噪声抑制能力。针对IBIS建模规范,作者提出了三维I-V曲面数据提取技术,并介绍了共模/差模电流分离、片上端接处理以及V-T表生成的解决方案。文章还探讨了差分电容(C_diff)的测量方法和数据简化策略,为复杂差分缓冲器的精确建模提供了系统化的技术路径。

一只豌豆象的博客 1281

【电路设计】SERDES与pcie

明确通信接口需要达到什么样的数据速率、信号完整性以及系统中各个部件的互相作用。2.

数字人生 4563

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, S1 and S2, each stack containing...

diansuoku1565的博客 269

【毕业设计】基于雷达与深度学习的摔倒检测——雷达数据集的建立

运动物体的微多普勒效应为人体动作识别提供了可能,基于雷达的居家检测具有良好的隐私保护性,且不易受环境因素影响(如光照、温度等),近年来已受到国内外学者的广泛关注。基于雷达与深度学习的摔倒检测使用自建的雷达数据集进行人体摔倒检测的研究。雷达数据集的建立分为雷达数据采集和雷达数据处理两部分工作。

洋洋Young的博客 3403

POJ 3087 Shuffle'm Up

POJ 3087 Shuffle’m Up(简单模拟题) 题目大意: 给出两个长度为len的字符串s1, s2和一个长度为2 * len的字符串s12,每次先让s2先s1后先后依次取一个字符得到一个长度为2 * len 的字符串s,如果发现得到的字符串s与s12相等就输出交换的次数,否则让s的左半边等于s1右半边等于s2再进行上面的变换,如果无法使的变换后的s == s12则输出-1。 具体思路:...

指弹键盘哼民谣 574

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

POJ 3087 Shuffle'm Up(洗牌)

POJ3087 Shuffle'm Up(洗牌) TimeLimit:1000MSMemoryLimit:65536K Description- 题目描述   A common pastime for poker players at a poker table is to shuffle stacks of chips. Shufflin...

145

老版QQ原生表情gif动态

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

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

Shuffle'm Up|POJ3087

Shuffle’m Up POJ3087 #include<iostream> #include<string> #include<set> using namespace std; int flag, len, ans; set<string> mySet; void f(string s1, string s2, string s12) { ...

My Blog 159

[POJ 3087] Shuffle'm Up

[POJ 3087] Shuffle'm Up 题目链接:http://poj.org/problem?id=3087 1 #include&lt;cstdio&gt; 2 #include&lt;cstring&gt; 3 4 using namespace std; 5 6 char ss[1000][220];...

Youpeng 125

POJ 3087 Shuffle'm Up

题意:给出两个字符串,d2字符串在下,d1字符串在上,交叉组成一个字符串,判断初始串进行若干次操作后是否能到目标串 链接:http://poj.org/problem?id=3087 思路:模拟即可 注意点:需要记录该位置是否到达过,用map作为hash即可 以下为AC代码: Run ID User Problem Result Memory Time

luminous11的专栏 370

poj3087 Shuffle'm Up

题意: 已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12, 再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去。给定输入s1和s2的初始状态 以及 预想的最终状态s12。 解题思路:模拟题 用map存储洗牌过后的状态字符串 然后根据洗牌的状态去对比题目给定的字符串 直接看代码 package 简单搜索; impo

功不成身已退的博客 356

poj 3087 Shuffle'm Up

http://poj.org/problem?id=3087 Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description A common pastime for poker

大太阳 407
上一篇: Sort 归并排序求逆序对
下一篇: FFT
mwhybmj
博客等级 码龄10年 8粉丝 74原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值