POJ 3087 Shuffle‘m Up 模拟 G++

本文探讨了两摞各C张不同颜色扑克牌的洗牌过程。通过特定的洗牌方式,文章研究如何达到预设的目标状态,并分析了实现该状态所需的洗牌次数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <iostream>
#include <string>
#include <map> 
using namespace std;
//抄博友好程序 用set巧妙 运行一下博友程序 
//AHAH A在最低部 
map<string,int>mp;
int main()
{
	int n;
	cin>>n;
	//cout<<n<<endl;
	int ca=0;
	while(n!=0)
	{
		mp.clear();
		n--;
		ca++;
		int c;
		cin>>c;
		//cout<<c<<endl;
		string s1,s2;
		cin>>s1>>s2;
		//cout<<s1<<endl<<s2<<endl;
		string s;
		cin>>s;
		//cout<<s<<endl;
		int js=0;
		string ts;
		ts.clear();
		string ta,tb;
		ta.clear();
		tb.clear();
		ta=s2;//抄博友程序  学好英语 
		tb=s1;//抄博友程序 
		//ta=s1; 
		//tb=s2; 		
		int flag=0;
		while(1)
		{
			if(ts==s)
			{
				break;
			}
			js++;
			ts.clear();
			for(int i=0;i<c;i++)
			{
				ts=ts+ta[i];
				ts=ts+tb[i];
			}
			//cout<<ts<<endl;
			ta=ts.substr(c,c);
			tb=ts.substr(0,c);
			//cout<<ta<<endl;
			//cout<<tb<<endl;	
			//if((ta==s1)&&(tb==s2))//博友程序巧妙
			if(mp[ts]==1)//抄博友程序 巧妙 学map用法 
			{
				flag=1;
				break;
			}
			mp[ts]=1;			
		}
		cout<<ca<<" ";
		if(flag==1)
		{
			cout<<-1<<endl;
		}else
		{
			cout<<js<<endl;
		}
	}
	return 0;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值