题目:

现有字符串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,后半部分作为s2,重复上述过程

输入:

第一行T(1≤T≤1000),代表有T组数据.

每组数据第一行len(1≤len≤100),第二行长度为len的字符串s1,第三行长度为len的字符串s2,第四行长度为2*len的字符串s12。

输出:

首先输出处理数据组的编号(编号从1开始)

再输出变换次数并换行。

注意两个数字之间有空格。

对于变换次数,如果无需变换直接得到s12,那么输出0,如果无论怎么变换都不会得到s12,那么输出 -1。

样例:

分析:简单的模拟,return-1的条件随便给了一个就水过了

#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<numeric>
#include<cmath>
#include<queue>
#include<vector>
#include<set>
#include<cctype>
#define PI acos(-1.0)
const int INF = 0x3f3f3f3f;
const int NINF = -INF - ;
typedef long long ll;
using namespace std;
string a, b, c;
int n;
int func()
{
int num = ;
string temp;
temp = a + b;
//cout << temp << endl;
while (temp != c)
{
if (num == * n) return -;
a = temp.substr(, n);
b = temp.substr(n, n);
//cout << a << ' ' << b << endl;
//break;
int flag = ;
for (int i = ; i < n; ++i)
temp[flag++] = b[i], temp[flag++] = a[i];
num++;
}
return num;
}
int main()
{
int T, t = ;
cin >> T;
while (T--)
{
t++;
cin >> n;
cin >> a >> b >> c;
int num = func();
cout << t << ' ' << num << endl;
}
return ;
}

POJ3087 Shuffle'm Up的更多相关文章

  1. poj3087 Shuffle'm Up(模拟)

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

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

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

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

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

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

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

  5. poj3087 Shuffle'm Up

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

  6. POJ3087 Shuffle'm Up 简单模拟

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

  7. POJ3087 Shuffle'm Up(模拟)

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

  8. poj3087 Shuffle'm Up(bfs)

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

  9. poj分类解题报告索引

    图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...

随机推荐

  1. Deutsch lernen (03)

    1. das Gewerbe, - 行业 Was ist Ihr Gewerbe? Welches Gewerbe treibt er? treiben - trieb - getrieben  从事 ...

  2. 【sqli-labs】 less10 GET - Blind - Time based. - Double quotes (基于时间的双引号盲注)

    这个和less9一样,单引号改完双引号就行了 http://localhost/sqli/Less-10/?id=1" and sleep(5)%23 5s后页面完成刷新 http://lo ...

  3. c# cookie帮助类

    using System; using System.Collections.Generic; using System.Text; using System.Web; namespace Matic ...

  4. Office 2013 提示找不到 Office.zh-cn\XXXXX

    1.先卸载Office 2013(已经卸载了的无视这一步)2.卸载Office 2013 后把C:\ProgramData\Microsoft\OFFICE文件删掉.3.删除下列注册信息1).依次点击 ...

  5. PAT_A1125#Chain the Ropes

    Source: PAT A1125 Chain the Ropes (25 分) Description: Given some segments of rope, you are supposed ...

  6. esp32(M5STACK)在线体验(Ubuntu)

    我们往m5stack烧录的固件是可以在线编程的 具体使用方法可以参考   https://github.com/m5stack/M5Cloud/blob/master/README_CN.md     ...

  7. RabbitMQ学习总结(1)——基础概念详细介绍

    一.基础概念详细介绍 1.引言 你是否遇到过两个(多个)系统间需要通过定时任务来同步某些数据?你是否在为异构系统的不同进程间相互调用.通讯的问题而苦恼.挣扎?如果是,那么恭喜你,消息服务让你可以很轻松 ...

  8. APIO 2017 游记

    //第一次写游记,只是流水账...结果好像确实只去游了…… day-11 省选挂了,即将退役……(然而apio之后得知并没有退役,感谢放我一条活路)(吐槽出题人考完才造数据,题目没有子任务之类的玩意, ...

  9. [bzoj2631]tree_LCT

    tree bzoj-2631 题目大意:给定一个n个点的树,每个点的初始权值为1,支持:删边加边(这两个操作同时进行,保证操作之后还是一棵树),路径加,路径乘,查询路径和. 注释:$1\le n,q\ ...

  10. MYSQL 技术内幕 博客学习

    http://blog.csdn.net/CCyutaotao/article/category/6147849/3