POJ3087 Shuffle'm Up 简单模拟
2016-01-28 13:22
357 查看
题意:就是给你两副扑克,然后一张盖一张洗牌,不断重复这个过程,看能不能达到目标的扑克顺序
分析:然后就模拟下,-1的情况就是有循环节
View Code
分析:然后就模拟下,-1的情况就是有循环节
#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> #include<map> #include<queue> #include<stdlib.h> #include<string> #include<set> using namespace std; typedef long long LL; const int maxn=1005; const int INF=0x3f3f3f3f; set<string>s; char a[maxn],b[maxn],now[maxn*2]; string res; int ans,c,T; void dfs(int pos) { int x=1,y=1; for(int i=1; i<=c*2; ++i) { if(i%2)now[i]=b[y++]; else now[i]=a[x++]; } now[c*2+1]='\0'; string temp=now+1; if(temp==res) { ans=pos; return; } if(s.find(temp)==s.end()) s.insert(temp); else return; for(int i=1; i<=c; ++i) { a[i]=now[i]; b[i]=now[i+c]; } dfs(pos+1); } int main() { scanf("%d",&T); for(int i=1; i<=T; ++i) { s.clear(); scanf("%d%s%s",&c,a+1,b+1); cin>>res; ans=INF; dfs(1); printf("%d ",i); if(ans==INF)printf("-1\n"); else printf("%d\n",ans); } return 0; }
View Code
相关文章推荐
- C#反射技术的简单操作(读取和设置类的属性)
- php爬虫:知乎用户数据爬取和分析
- Leetcode Best Time to Buy and Sell Stock with Cooldown
- ROS学习——入门篇(1)学习步骤
- 使用HashMap须要注意的事儿:不要暴露Map.entry给外部不可信代码Map.entrySet()
- 轻松学会多线程(四)——synchronized同步keyword知多少
- oracle 行转列-WMSYS. wm_contact的运用
- 一万小时定律
- (有码)和屏幕有关的事件传递Touch
- Python 科学计算
- 谈谈对攻读计算机研究生的看法
- pcduino v2安装opencv2.4.8
- Doc12(innerText与innerHTML及兼容性写法)
- 基于表单数据的封装,泛型,反射以及使用BeanUtils进行处理
- 基于表单数据的封装,泛型,反射以及使用BeanUtils进行处理
- Leetcode Permutations II
- EtherChannel(PAgP,LACP)
- deploy 自己编写的 QT 程序 (window下打包程序)
- 设计模式:适配器模式
- SQL Server管理及开发工具(Navicat for SQL Server)v11.2.13