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 ...
随机推荐
- AI.框架理论.语义网.语言间距.孤单
刷个博客,转载自于科学网:AI.框架理论.语义网.语言间距.孤单 一:引言: AI几乎是计算机科学家的梦想,自动化比计算机发展的要早的多.早期的自动化节省了大量人力,激发了人类懒惰的滋长和对自身进化缓 ...
- linux环境jdk安装及配置
linux环境jdk安装及配置 linux环境jdk安装及配置 1.下载jkd( http://www.oracle.com/technetwork/java/javase/downloads/ind ...
- eclipse中导入maven项目:org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.proje
org.codehaus.plexus.archiver.jar.Manifest.write(java.io.PrintWriter) 解决方法为:更新eclipse中的maven插件 1.help ...
- MVC控制器返回值
public ActionResult Index(string id)//主页 //参数string searchString 访问方式为index?searchString=xxxx .参数str ...
- linux下怎么退出telnet
在运维过程中,常常会telnet某个ip端口,如果 能telnet通,怎么退出呢 ? 1.telnet 63.172.25.18 6463 回车 Trying 63.172.25.18... Conn ...
- 解析python部分常用魔术方法
def __add__(self, *args, **kwargs): # real signature unknown """ Return self+value. & ...
- scrapy-redis让redis不止使用db0
废话不多说,直接在 custom_settings 设置即可 代码: class MySpider(RedisSpider): """Spider that reads ...
- eas之kdtable格式化
设置表.列.行或单元的格式化字符串 // 设置表table.getStyleAttributes().setNumberFormat(formatString); // 设置列column.getSt ...
- Call to undefined function openssl_decrypt()
laravel报错: Call to undefined function openssl_decrypt() 需要打开php.ini中的扩展: extension=php_openssl.dll
- 共享内存、网络(day13)
一.共享内存 .获取一个键值 ftok() .使用键值获取共享内存的id shmget() #include <sys/ipc.h> #include <sys/shm.h> ...