题目链接

题意:有两个字符串s1,s2;经过交叉问是否得到字符串s,不能输出-1,能就输出交叉的次数

每次重组的串都是s2开始,重新组合时,前面一半是s1,后一半s2;

#include<stdio.h>
#include<vector>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#define N 250
using namespace std; int main()
{
int T, t=, n, ans, j;
scanf("%d", &T);
while(T--)
{
char s1[N]={}, s2[N]={}, s[N]={}, str[N]={};//记得初始化;
map<string,int>maps;//个人理解为字符串的值;
int flag = ;
scanf("%d", &n);
scanf("%s%s%s", s1, s2, s);
ans = ;
while()
{
ans++;
j=;
for(int i=; i<n; i++)
{
str[j++] = s2[i];
str[j++] = s1[i];
}
s[j]='\0';
if(strcmp(str, s)==)break;
if(maps[str]==){flag=;break;}//导致循环;
maps[str]=;//存在过; strncpy(s1, str, n);
strncpy(s2,str+n, n);//更新s1,s2;
}
if(flag==)
printf("%d -1\n", t++);
else
printf("%d %d\n", t++, ans);
}
return ;
}

Shuffle'm Up---poj3087的更多相关文章

  1. 洗牌Shuffle'm Up POJ-3087 模拟

    题目链接:Shuffle'm Up 题目大意 模拟纸牌的洗牌过程,已知两个牌数相等的牌堆.求解经过多少次洗牌的过程,使牌的顺序与目标顺序相同. 思路 直接模拟,主要是字符串的操作.问题是,如何判断出不 ...

  2. poj3087 Shuffle'm Up(模拟)

    Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10766   Accepted: 4976 Des ...

  3. POJ3087:Shuffle'm Up(模拟)

    http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...

  4. POJ-3087 Shuffle'm Up (模拟)

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

  5. POJ3087 Shuffle'm Up —— 打表找规律 / map判重

    题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS   Memory Limit: 65536K Total Sub ...

  6. poj3087 Shuffle'm Up

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

  7. POJ3087 Shuffle'm Up 简单模拟

    题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...

  8. POJ3087 Shuffle'm Up(模拟)

    题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...

  9. poj3087 Shuffle'm Up(bfs)

    http://poj.org/problem?id=3087 注意复制字符串的时候,要在末尾加上'\0',否则导致strcmp出错. 还有就是开数组大小的时候看清楚一点,别开错了debug了好久. # ...

  10. POJ3087 Shuffle'm Up

    题目: 现有字符串s1.s2.s12,其中s1.s2的长度为len,s12的长度为2*len. 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=0 ...

随机推荐

  1. Four Ways to Create a Thread

    Blaise Pascal Magazine Rerun #5: Four Ways to Create a Thread   This article was originally written ...

  2. Selenium 基本用法

    如下,使用 Selenium 打开淘宝首页并获取页面源代码: from selenium import webdriver browser = webdriver.Chrome() # 声明一个浏览器 ...

  3. 使用Postfix和Dovecot收发电子邮件

    邮件应用协议包括: 简单邮件传输协议(SMTP),用来发送或中转发出的电子邮件,占用tcp 25端口. 第三版邮局协议(POP3),用于将服务器上把邮件存储到本地主机,占用tcp 110端口. 第四版 ...

  4. vue的首页渲染了两次的原因以及解决方法

    现在在用vue做一些单页面应用的东西,遇到了些许问题啊,比如我再渲染首页的时候,会渲染两次,查看了一下原因,原来是在写路由的时候写的格式错了: 这样的时候,初始的时候就是加载的exam_list页面, ...

  5. [微信小程序]计算自己手机到指定位置的距离

    目的: 根据目的地的坐标计算自己手机的位置离目的地的距离的 核心思路: 后续操作必须等所有异步请求都返回了才能继续 使用 const qqmap = require("../../utils ...

  6. sklearn算法库的顶层设计

    sklearn监督学习的各个模块 neighbors近邻算法,svm支持向量机,kernal_ridge核岭回归,discriminant_analysis判别分析,linear_model广义线性模 ...

  7. 【大数据系列】在windows下连接linux 下的hadoop环境进行开发

    一.下载Eclipse并安装 二.下载exlipse的hadoop plugin 三.打开Map Reduce视图 Window --> Perspective --> Open pers ...

  8. 删除RHSA文件方法

    DEL /F /A /Q \\?\%1RD /S /Q \\?\%1新建一个批处理文件,包含上面两行代码,然后将要删除的文件拖放进里面就OK!

  9. 精品绿色便携软件 & 录制操作工具

    https://www.vtaskstudio.com/index.php  录制宏工具 https://soft.anruan.com/29821/  TinyTask V1.5 电脑版 https ...

  10. Mysql 忘记 root密码解决

    1 stop mysql Ubuntu/Debian: sudo /etc/init.d/mysql stop CentOs: sudo /etc/init.d/mysqld stop 2 启动saf ...