POJ 3087 Shuffle'm Up

Codex实战:基于LLM的PR自动化安全审查如何提升开发效率与代码安全 在软件开发生命周期中,安全漏洞的早期发现与修复至关重要。静态应用安全测试(SAST)通过分析源代码,无需运行程序即可识别潜在的安全风险,如SQL注入、硬编码密钥等常见漏洞。其核心原理是基于预定义规则集进行模式匹配,旨在将安全防护左移,降低修复成本。随着人工智能技术的发展,大型语言模型(LLM)为代码安全分析带来了新的范式。LLM能够理解代码上下文与意图,进行推理分析,从而可能发现传统规则库难以覆盖的逻辑漏洞。这种技术价值在于,它不仅提升了漏洞发现的准确性和深度,还能以自然语言交互方式提供修复建议,极大地降低 阅读详情

Shuffle’m Up

https://vjudge.net/problem/POJ-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 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

C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <string>

using namespace std;

map<string, int> m;
string s1, s2, s3;
string tmp;
int n;

struct node{
	string s;
	int step;
};

int bfs()
{
	queue<node> q;
	node now;
	tmp = "";
	for(int i = 0; i < n; i ++)
	{
		tmp += s2[i];
		tmp += s1[i]; 
	}
	now.s = tmp;
	now.step = 1;
	q.push(now);
	m[now.s] ++;
	while(!q.empty())
	{
		now = q.front();
		q.pop();
		if(now.s == s3)
			return now.step;
		s1 = now.s.substr(0, n);
		s2 = now.s.substr(n, n);
		tmp = "";
		for(int i = 0; i < n; i ++)
		{
			tmp += s2[i];
			tmp += s1[i]; 
		}
		if(!m[tmp])
		{
			now.s = tmp;
			now.step += 1;
			m[tmp] ++;
			q.push(now);
		}
	}
	return -1;
}

int main()
{
	int t;
	scanf("%d", &t);
	for(int i = 1; i <= t; i ++)
	{
		scanf("%d", &n);
		cin >> s1 >> s2 >> s3;
		m.clear();
		int ans = bfs();
		printf("%d %d\n", i, ans);
	}
	return 0;
}
常学常新:《Attention Is All You Need》万字解读! 阅读详情

相关推荐

图像传感器与信号处理——详解CCD与CMOS图像传感器

一文详解CCD与CMOS图像传感器一文详解CCD与CMOS图像传感器1. 图像传感器性能关键词1.1 噪声1.2 暗电流 一文详解CCD与CMOS图像传感器 本文主要总结了CCD与CMOS传感器的原理知识,参考书籍为《数码相机中图像传感器和信号处理》,英文版为《Image Sensors And Signal Processing for Digital Still Cameras》 1. 图像传...

weixin_44580210的博客 2万+

Shuffle'm Up POJ - 3087(详细注释)

现有字符串s1、s2、s12,其中s1、s2的长度为len,s12的长度为2*len。 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=00000 变换后的序列 s=0101010101 假设s1=12345,s2=67890 变换后的序列 s=6172839405 如果s和s12完全相同,那么输出变换次数 如果不完全相等,s的前半部分作为s1...

weixin_44641254的博客 256

自动驾驶——最优控制算法(LQR)工程化总结

到近段时间,真正在我们的控制器上运行最优控制算法(LQR),一步一个脚印,从开始只是知道其“控制理论”的阶段、再到对着一堆网上的资料和公式一筹莫展不知何着手、再到初步实现了LQR算法的开发(但是使用的扭矩环控制,控制的不好,而且由于各种原因被delay,迟迟无法落地),直到大上个星期,泊车平台有此LQR开发需求,又重新了开始了算法的研发,用时一个周时间完成了算法开发,然后再用一个周时间进行实车最优控制算法验证与调试,取得了很大的进展,由于执行器是转角控制的,这无疑少了很多的工作量。

qq_40464599的博客 2787

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

【架构师面试-缓存与搜索-1】-缓存与缓存置换策略源码实现

1:什么是缓存 缓存:加速数据访问的存储,降低延迟(latency),提升吞吐量(Throughput)的利器。 1:缓存演进历史 1. 查库 2. ConcurrentHashMap 3. LRU 4. Guava Cache 5. 分布式缓存(redis,MemCache) 6. 多级缓存 2:在什么地方加缓存 缓存对于每个开发者来说是相当熟悉了,为了提高程序的性能我们会去加缓存,但是在什么地方加缓存,如何加缓存呢? 举个栗子:假设一个网站,需要提高性能,缓存可以放在浏览器,可以放

chongfa2008的博客 6437

Apache Kylin 命令注入漏洞复现(CVE-2020-1956)

Apache Kylin 中的静态 API 存在安全漏洞,可以将os命令与用户输入字符串连接起来,攻击者可以在Kylin没有任何保护或验证的情况下执行任何os命令。

0xSec 1558

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

简谈基于FPGA的千兆以太网设计

简谈基于FPGA的千兆以太网设计 今天给大侠带来简谈基于FPGA的千兆以太网设计,话不多说,上货。 今天我们来简单的聊一聊以太网,以太网在FPGA学习中属于比较高级的内容了,有些大侠肯定会感觉以太网学习起来非常不容易。其实,我可以告诉大家,前期学习的基础打扎实了,后期的学习也没那么难。总之就是说难没那么难,说容易也不是那么容易。那么,言归正传,下面让我们一起来聊一聊以太网的学习。 说起以太网,大家可能就会想到百兆以太网、千兆以太网以及万兆以太网等等。局域以太网从10M开始发展,经历几多的变迁,发展到现

3619

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

Codex 接入国产大模型完整指南:CC-Switch 与 Codex++ 的工程化选型

Codex 默认走 OpenAI Responses API,而 DeepSeek、GLM、Kimi 等国产模型只提供 OpenAI-compatible 的 Chat Completions——两套协议在消息结构、流式响应、reasoning 字段、tool call 上都不兼容,所以"改个 Base URL + 填国产 Key"这种朴素操作根本跑不通。本文从架构师视角出发,把 Codex 接入国产大模型这件事讲透:先剖析协议链路到底卡在哪,再对比 CC-Switch和 Codex++两套主流方案的差异

少说,多做 3850

Yocto系列讲解[入门篇] 2 - 演示运行qemux86-64虚拟机

手把手教大家怎么编译Yocto,并运行一个qemux86虚拟机

fulinux的博客 1万+

[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

【YOLOv11多模态融合改进】| CVPR2025 LCA轻量交叉注意力 双向模态交叉引导 + 双支路噪点抑制,兼顾纹理与热目标特征融合

可见光模态富含纹理、色彩、边缘细节,但夜间/低照度场景信噪比极低,暗区噪声泛滥;红外模态依靠热辐射凸显弱小目标、暗区物体轮廓,但缺失真实色彩与精细纹理。简单拼接/逐加融合仅做浅层特征叠加,无法建立可见光纹理、红外热特征的双向引导关联,两类模态互补信息无法精准互通;普通自注意力仅单模态内部建模,跨模态交互匮乏,红外热目标易被可见光暗噪声淹没,可见光有效纹理易被红外灰度信息覆盖;

Limiiiing的博客 115

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

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

SAP B1中文培訓教材_SDK

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

Shuffle'm Up POJ - 3087

Shuffle’m Up POJ - 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 and S2, each stac...

ln2037的博客 197

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

poj3087 Shuffle'm Up

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

功不成身已退的博客 356

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

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

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

【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

poj3087 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 C chips. Eac

zxy160的博客 709
上一篇: POJ 3126 Prime Path
下一篇: HDU 1495 非常可乐
剑气扬名
博客等级 码龄7年 24粉丝 79原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值