题目:

现有字符串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. 网上找的JS截取字符串(含中文)

    <script> /* 2007-11-28 XuJian */ //截取字符串 包含中文处理 //(串,长度,增加...) function subString(str, len, ha ...

  2. servlet-后台获取form表单传的参数

    前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> & ...

  3. python2打印list中文内容防乱码

    zh_ls = ['人','民'] print str(zh_ls).decode("string_escape")

  4. JAVA;使用java.awt.Image的不稳定性

    在使用awt的image时候,不是能时时获取到图像的宽和高, GetWidth()函数偶尔得到的值为-1,暂时没有找到解决方法. 代码: public class picture extends JF ...

  5. 团体程序设计天梯赛-练习集-L1-034. 点赞

    L1-034. 点赞 时间限制 200 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 微博上有个“点赞”功能,你可以为你喜欢的博文点个赞表示支持 ...

  6. UI Testing

    UI Test能帮助我们去验证一些UI元素的属性和状态.Apple 在 Xcode 7 中新加入了一套 UI Testing 的工具,其目的就是解决自动化UI测试这个问题.新的 UI Testing ...

  7. html第三节课

    表单 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.o ...

  8. C++引用、类型转换、类和对象(day03)

    十 C++的引用(Reference) 引用型函数参数 )将引用用于函数的参数,可以修改实参变量的值,同时也能减小函数调用的开销. )引用参数有可能意外修饰实参的值,如果不希望修改实参变量本身,可以将 ...

  9. laravel Job 和事件

    在做项目的时候,一直对Job和Event有个疑惑.感觉两者是相同的东西,搞不清楚两者的区别在哪里!经过一段时间的琢磨和查找了相关的资料,对Job和Event做了一些总结,以便记忆. Job Job既可 ...

  10. 将 Vue 组件库发布到 npm

    制作了一套自己的组件库,并发布到npm上,项目代码见 GitHub . 前期准备 有一个npm账号 安装了vue-cli 搭建项目 vue init webpack hg-vcomponents cd ...