Test instructions: is to give you two pairs of poker, and then a cover a shuffle, and constantly repeat the process to see if you can achieve the goal of the poker order
Analysis: Then the simulation, 1 of the situation is that there is a cyclic section
#include <cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<cmath>#include<map>#include<queue>#include<stdlib.h>#include<string>#include<Set>using namespaceStd;typedefLong LongLL;Const intmaxn=1005;Const intinf=0x3f3f3f3f;Set<string>s;Chara[maxn],b[maxn],now[maxn*2];stringRes;intans,c,t;voidDfsintPOS) { intx=1, y=1; for(intI=1; i<=c*2; ++i) {if(i%2) now[i]=b[y++]; Elsenow[i]=a[x++]; } now[c*2+1]=' /'; stringtemp=now+1; if(temp==Res) {ans=POS; return; } if(S.find (temp) = =s.end ()) S.insert (temp); Else return; for(intI=1; i<=c; ++i) {A[i]=Now[i]; B[i]=now[i+c]; } DFS (POS+1);}intMain () {scanf ("%d",&T); for(intI=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"); Elseprintf"%d\n", ans); } return 0;}
View Code
POJ3087 Shuffle ' m up simple simulation