POJ3087 Shuffle'm Up
题目:
现有字符串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的更多相关文章
- poj3087 Shuffle'm Up(模拟)
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10766 Accepted: 4976 Des ...
- POJ3087:Shuffle'm Up(模拟)
http://poj.org/problem?id=3087 Description A common pastime for poker players at a poker table is to ...
- POJ-3087 Shuffle'm Up (模拟)
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up —— 打表找规律 / map判重
题目链接:http://poj.org/problem?id=3087 Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Sub ...
- poj3087 Shuffle'm Up
Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuff ...
- POJ3087 Shuffle'm Up 简单模拟
题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序 分析:然后就模拟下,-1的情况就是有循环节 #include<cstdio> #include&l ...
- POJ3087 Shuffle'm Up(模拟)
题目链接. AC代码如下; #include <iostream> #include <cstdio> #include <cstring> #include &l ...
- poj3087 Shuffle'm Up(bfs)
http://poj.org/problem?id=3087 注意复制字符串的时候,要在末尾加上'\0',否则导致strcmp出错. 还有就是开数组大小的时候看清楚一点,别开错了debug了好久. # ...
- poj分类解题报告索引
图论 图论解题报告索引 DFS poj1321 - 棋盘问题 poj1416 - Shredding Company poj2676 - Sudoku poj2488 - A Knight's Jou ...
随机推荐
- CVPR2015深度学习回顾
原文链接:http://www.csdn.net/article/2015-08-06/2825395 本文做了少量修改,仅作转载存贮,如有疑问或版权问题,请访问原作者或告知本人. CVPR可谓计算机 ...
- 【sqli-labs】 less5 GET - Double Injection - Single Quotes - String (双注入GET单引号字符型注入)
双注入查询可以查看这两篇介绍 https://www.2cto.com/article/201302/190763.html https://www.2cto.com/article/201303/1 ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(10)--在Web界面上实现数据的导入和导出
http://www.cnblogs.com/wuhuacong/p/3873498.html 数据的导入导出,在很多系统里面都比较常见,这个导入导出的操作,在Winform里面比较容易实现,我曾经在 ...
- vue向数组中动态添加数据
vue中数据更新通过v-model实现,向数组中添加数据通过push()实现,向shortcuts数组中动态添加newShortcut对象中的title和action this.shortcuts.p ...
- Day 18 hashlib,logging模块
hashlib 模块 作用:hash是一种算法,主要提供SHA1,SHA224,SHA256,SHA384,SHA512,MD5算法,该算法接受传入的内容,经过运算得到一串hash值 特点: 1.只要 ...
- 【剑指Offer】33、丑数
题目描述: 把只包含质因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含质因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数 ...
- CodeIgniter-CI之MySQL
首先我们需要进行一下配置,这里需要修改的文件为application目录下的config目录下的database.php文件,我们修改相应的配置项,比如这里是我的配置情况: 通常我们在操作数据库之前, ...
- Idea里面的postfix
感谢慕课网IntelliJ IDEA神器使用技巧 闪电侠讲师,感觉有些工具真的是听听别人讲的比自己琢磨快很多 https://www.imooc.com/learn/924 也可以这样找到postfi ...
- QT中tableview不能更新数据,why?
model->select(); //model->removeColumn(0);++++++++++++++++++++ //model->setHeaderData(model ...
- orcale 单行函数之数字函数, 日期函数
日期函数: 案例: