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,重复上述过程。

直接模拟,注意给出的顺序是从底到上的。

代码总览

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#define nmax 205
using namespace std;
char str1[nmax],str2[nmax],str[nmax];
int t,ans,n;
void change(char temp[])
{
int pos = 0;
for(int i = 0;i<n;++i){
temp[pos++] = str2[i];
temp[pos++] = str1[i];
}
temp[2*n] = '\0';
ans++;
}
void split(char temp[])
{
int i;
for(i = 0;i<n;++i)
str1[i] = temp[i];
str1[i] = '\0';
for(int j = 0;j<n;++j,++i)
str2[j] = temp[i];
str2[i] = '\0';
}
void bfs()
{
char temp[nmax];
memset(temp,0,sizeof(temp));
change(temp);
set<string> s;
s.clear();
while(1){
if(strcmp(temp,str) == 0) return;
if(s.count(temp) == 1){
ans = -1;
return;
}else{
s.insert(temp);
}
split(temp);
change(temp);
}
}
int main()
{
scanf("%d",&t);
for(int i = 1; i<=t;++i){
ans = 0;
scanf("%d",&n);
scanf("%s",str1);
scanf("%s",str2);
scanf("%s",str);
bfs();
printf("%d %d\n",i,ans);
} return 0;
}

POJ.3087 Shuffle'm Up (模拟)的更多相关文章

  1. POJ 3087 Shuffle'm Up (模拟+map)

    题目链接:http://poj.org/problem?id=3087 题目大意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块 ...

  2. poj 3087 Shuffle'm Up (模拟过程)

    Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...

  3. POJ 3087 Shuffle'm Up 模拟,看着不像搜索啊

    题意:给定s1,s1两副扑克,顺序从下到上.依次将s2,s1的扑克一张一张混合.例如s1,ABC; s2,DEF. 则第一次混合后为DAEBFC. 然后令前半段为s1, 后半段为s2. 如果可以变换成 ...

  4. POJ 3087 Shuffle'm Up(洗牌)

    POJ 3087 Shuffle'm Up(洗牌) Time Limit: 1000MS    Memory Limit: 65536K Description - 题目描述 A common pas ...

  5. DFS POJ 3087 Shuffle'm Up

    题目传送门 /* 题意:两块扑克牌按照顺序叠起来后,把下半部分给第一块,上半部给第二块,一直持续下去,直到叠成指定的样子 DFS:直接模拟搜索,用map记录该字符串是否被搜过.读懂题目是关键. */ ...

  6. POJ 3087 Shuffle'm Up

    Shuffle'm Up Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  7. poj 3087 Shuffle'm Up ( map 模拟 )

    题目:http://poj.org/problem?id=3087 题意:已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,再将s12的最底下的c块牌归为s ...

  8. POJ 3087 Shuffle&#39;m Up(模拟)

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7404   Accepted: 3421 Desc ...

  9. POJ 3087 Shuffle'm Up【模拟/map/string】

    Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14471 Accepted: 6633 Descrip ...

随机推荐

  1. 译图智讯VIN码识别助力汽配商转型升级

    汽配猫是上海佳驰经合能源科技有限公司自主开发的汽车配件B2B网上商城及服务平台,该平台依托互联网云技术.利用创新的商业模式及互联网思维,整合汽配产业链优秀资源,为汽车维修保养企业等产业链各方面提供汽配 ...

  2. Unity中StopCoroutine不起作用怎么办

    1,只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine(string CoroutineName)停用. 2, public Coroutine coroutine ...

  3. 每天一个linux命令集

    linux命令汇总,装载来自: http://www.cnblogs.com/peida/category/309012.html

  4. ES6的新特性(17)——Generator 函数的异步应用

    Generator 函数的异步应用 异步编程对 JavaScript 语言太重要.Javascript 语言的执行环境是“单线程”的,如果没有异步编程,根本没法用,非卡死不可.本章主要介绍 Gener ...

  5. PSP1130

    PSP时间图: 类型 任务 开始时间 结束时间 净时间 中断时间 日期 开会 开会 16:17 16:50 33 0 20171027 开会 开会 17:00 17:22 22 0 20171028 ...

  6. c# 简单日志记录

    FileStream fs = new FileStream(System.AppDomain.CurrentDomain.BaseDirectory + "log.txt",Fi ...

  7. tomcat开发环境配置

    1.环境配置教程 环境变量.安装版.配置版 2.编写启动tomcat的批处理文件 3.改变端口 4.虚拟目录

  8. 软工1816 · 第八次作业(课堂实战)- 项目UML设计(团队)

    本次作业博客 团队信息 队名:起床一起肝活队 原组长: 白晨曦(101) 原组员: 李麒 (123) 陈德斌(104) 何裕捷(214) 黄培鑫(217) 王焕仁(233) 林志华(128) 乐忠豪( ...

  9. 大白话Docker入门(一)

    摘要: #大白话Docker入门(一) 随着docker现在越来越热门,自己也对docker的好奇心也越来越重,终于忍不住利用了一些时间把docker学习一遍.目前的资料不少,但是由于docker的发 ...

  10. 多线程PV

    #include <STDIO.H> #include <windows.h> //#include "stdafx.h" #include <pro ...