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;
}
BME688传感器原理图设计,已量产(环境传感器) 在便携式空气质量监测、可穿戴健康设备这类低功耗场景中,BME688 这类集成了 VOC、温湿度、气压的四合一 MEMS 传感器越来越受欢迎 —— 它体积小、功耗低,刚好匹配便携设备的需求。但这类小信号传感器对电源噪声、电平匹配的要求很细,今天结合实际项目里的一款 BME688 接口电路,聊聊硬件设计的关键细节。 阅读详情

相关推荐

sldd数据字典导出为excel

sldd导出为excel

zpfjf的博客 2237

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

SillyTavern 向量存储配置踩坑记:从卡死到本地部署 Ollama 跑通

用此命令看到镜像就算成功。

qq_62483451的博客 1259

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

基于用户的协同过滤算法(userCF)

1.定义 userCF:当一个用户A需要个性化推荐时,可以先找到和他有相似兴趣的其他用户,然后把那些用户喜欢的、而用户A没有听说过的物品推荐给A。这种方法称为基于用户的协同过滤算法。 基于用户的协同过滤算法主要包括两个步骤: 2.第一步:找到和目标用户兴趣相似的用户集合。 利用行为的相似度计算兴趣的相似度。给定用户u和用户v,令N(u)表示用户u曾经有过正反馈的物品集合,令N(v)为用户v曾经有过...

jiangdongxiaobawang的博客 1万+

K8s私有仓库拉取镜像报错解决:x509 certificate signed by unknown authority

在Kubernetes环境中使用自签名证书的私有Harbor镜像仓库时,常会遇到证书验证失败的问题。本文将详细讲解如何解决这个常见的证书问题。Kubernetes版本:1.28.2容器运行时:containerd 1.6.20私有仓库:Harbor(使用自签名证书)(超简单搭建私有仓库Harbor-亲测无坑解决K8s私有仓库证书问题的关键在于正确配置容器运行时(本例中是containerd)信任私有仓库的证书。

lzz的博客 2140

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

Anaconda安装教程傻瓜教程

网上好多教程找的我心好累,为了方便新手安装,我这边整理了大致详细的教程,参考了好几个大佬的教程,废话不多说,直接开始~ **前言:**有人纠结先安装python还是安装anaconda,这边的建议是装anaconda,就不需要单独装python了。 其次,有小伙伴的Anaconda的安装分两种情况: 情况一:电脑现在没有装python或者现在装的可以卸载掉(装Anaconda时先卸python); 情况二:电脑目前装了python,但想保留它;

zlc2351951436的博客 5万+

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

智能车竞赛新手必看:单车定向组直线竞速与八字慢速实战技巧

本文为智能车竞赛新手提供单车定向组直线竞速与八字慢速的实战技巧,涵盖赛道分析、动力调校、传感器配置等关键环节。通过真实案例和代码示例,详细讲解如何平衡速度与稳定性,帮助选手避免常见失误,提升比赛成绩。特别针对智能车竞赛中的直线竞速和八字慢速项目,提供从硬件选型到临场策略的全方位指导。

weixin_28718793的博客 434

ESP32S3 TLS 握手WIFI可用但是在蜂窝热点下卡死:排查方法与根因

设备卡在等。

摸鱼专家 86

[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

11、AUTOSAR配置全解析:从运行实体到通信接口

本博客详细解析了在Simulink中使用AUTOSAR字典配置AUTOSAR运行实体(Runnables)、运行实体间变量(IRVs)、参数以及多种通信接口的过程。内容涵盖运行实体及其事件的配置、IRV和参数的属性设置,以及发送-接收接口、模式切换接口、客户端-服务器接口、非易失性数据接口、参数接口和触发接口的详细配置方法。通过这些步骤,开发者可以高效地构建符合AUTOSAR标准的汽车电子软件系统。

e3f4g5的博客 123

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

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

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

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

poj3087 Shuffle'm Up

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

功不成身已退的博客 356

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

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

余额充值