Shuffle'm Up---poj3087
题意:有两个字符串s1,s2;经过交叉问是否得到字符串s,不能输出-1,能就输出交叉的次数
每次重组的串都是s2开始,重新组合时,前面一半是s1,后一半s2;
#include<stdio.h>
#include<vector>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<map>
#define N 250
using namespace std; int main()
{
int T, t=, n, ans, j;
scanf("%d", &T);
while(T--)
{
char s1[N]={}, s2[N]={}, s[N]={}, str[N]={};//记得初始化;
map<string,int>maps;//个人理解为字符串的值;
int flag = ;
scanf("%d", &n);
scanf("%s%s%s", s1, s2, s);
ans = ;
while()
{
ans++;
j=;
for(int i=; i<n; i++)
{
str[j++] = s2[i];
str[j++] = s1[i];
}
s[j]='\0';
if(strcmp(str, s)==)break;
if(maps[str]==){flag=;break;}//导致循环;
maps[str]=;//存在过; strncpy(s1, str, n);
strncpy(s2,str+n, n);//更新s1,s2;
}
if(flag==)
printf("%d -1\n", t++);
else
printf("%d %d\n", t++, ans);
}
return ;
}
Shuffle'm Up---poj3087的更多相关文章
- 洗牌Shuffle'm Up POJ-3087 模拟
题目链接: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了好久. # ...
- POJ3087 Shuffle'm Up
题目: 现有字符串s1.s2.s12,其中s1.s2的长度为len,s12的长度为2*len. 是否可以通过一些操作使s1和s2转换合并成s12? 变换的操作规则如下: 假设s1=11111,s2=0 ...
随机推荐
- ice服务初探
http://masterkey.iteye.com/blog/182975 http://blog.csdn.net/moxiaomomo/article/details/6773979 http: ...
- mybatis 之 parameterType="Map"
// 获得品牌下的商品 Map<String, Object> params = new HashMap<String, Object>(); params.put(" ...
- php 建立 搜索 分词树
<?php /** * @author: xiaojiang 20140107 * php 建立分词树 * */ class Tree{ public $w = ''; public $subT ...
- 【Linux】使用 telnet 提示 Escape character is '^]'的意义
在linux/unix下使用telnet hostname port连接上主机后会提示Escape character is '^]' 这个提示的意思是按Ctrl + ] 会呼出telnet的命令行, ...
- Mysql错误:Duplicate entry '127' for key 'PRIMARY'的解决方法
有时候真是挺幸运,正当我自以为是地认为掌握了某个知识点的时候,现实就会马上出现另外一个问题,让我知道之前的认知是不全面的. 正如我上篇博文中所述,如果一个自增字段达到了上限,而且继续向里面插入数据的话 ...
- shell截取字符串的一些简单方法
一.使用${} 1.${var##*/}该命令的作用是去掉变量var从左边算起的最后一个'/'字符及其左边的内容,返回从左边算起的最后一个'/'(不含该字符)的右边的内容.使用例子及结果如下:
- Eclipse中如何在指定工程中搜索指定的字符串
1.点击Search: 2.在下拉框中先择Search. 3. 4. 5.选择Java 6.
- java(1) 编程基础
1.classpath 环境变量 * 当java虚拟机需要运行一个类时,会在classpath 环境变量中所定义的路径下寻找所需的class文件 2.java 的基本语法 * java 语言是严格区分 ...
- intelj idea编译项目报错,Error:ajc: The method getDestHost() is undefined
一.问题简述 这两天在idea中引入过aspectJ相关的东西,用到了aspectJ的编译器进行编译时织入. 结果今天在编译一个老项目时,(用到了lombok,lombok的idea插件会在javac ...
- vue Element-UI组件
一.UI组件 目的: 提高开发效率, 别人提供好一切, 拿过来直接用饿了么团队开源一个基于vue组件库 Element-UI ==> pc端 文档: http://element-cn.elem ...