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 ...
随机推荐
- js邮箱正则表达式的使用
在网页中插入邮箱输入框,当邮箱输入格式错误,给出提示.代码:function yy(){ var t = /^[A-Za-zd0-9]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[- ...
- fatal error C1083: 无法打开包括文件:“stdio.h
现象: vs2012一直fatal error C1083: 无法打开包括文件:"stdio.h" 不知道配置太多,动到了什么地方,出现了这个问题: 在: 解决方案--调试源文件 ...
- mysql手册操作
1.show table status 显示表状态 2.VERSION() 版本:CURRENT_DATE 当前日期: NOW() 当前时间:USER 当前用户 3.GRANT A ...
- Arduino LM35温度检测
一. 接线原理图 二.实物图 三.代码例子
- Scala: Types of a higher kind
One of the more powerful features Scala has is the ability to generically abstract across things tha ...
- C# MVC 获得程序运行路径
string filePath = System.Web.HttpContext.Current.Request.MapPath("~/Upload"); //由虚拟路径指定的服务 ...
- python 直接存入Excel表格
def write_excels(self, document): outwb = openpyxl.Workbook() outws = outwb.create_sheet(index=0) fo ...
- Codeforces Round #548 (Div. 2) B. Chocolates
You went to the store, selling
- Java 并行 (2): Monitor
转自:http://www.cnblogs.com/tomsheep/archive/2010/06/09/1754419.html 1. 什么是Monitor? Monitor其实是一种同步工具,也 ...
- html第八节课
导航 1.首先在<head>里面引用一个JQUERY的文件以用来制作鼠标点击动画效果(从网站上下载即可) 1 <script language="javascript&qu ...