Two questions mean the same thing.
The first question is 10 binary, the second one is 2 binary
are using the Fleury algorithm of the Euler loop to solve
Because I always want the small row in front, so I always first put the smaller number into the stack, and then the other array to receive the answer, but here again from the stack to export the answer to be inverted, it is important to note that
POJ 1780
1#include <cstdio>2#include <cstring>3#include <cmath>4 using namespacestd;5 #defineN 10000106 7 intAns[n], cnt[n], stack[n];8 intTop1, TOP2;9 intMoD;Ten voidEulerintv) One { A while(cnt[v]<Ten) - { - intw=v*Ten+Cnt[v]; thecnt[v]++; -stack[top1++]=W; -v=w%MoD; - } + } - + intMain () A { at //freopen ("In.txt", "R", stdin); - intN; - while(SCANF ("%d", &N), N) - { -TOP1 =0, TOP2 =0, mod = (int) Pow (10.0, (n1)*1.0); -stack[top1++] =0; inmemset (CNT,0,sizeof(CNT)); -cnt[0]++; to while(TOP1) + { -ans[top2++] = stack[--TOP1]; the intv = ans[top2-1]/Ten; * Euler (v); $ }Panax Notoginseng for(intI=1; I<=n; i++) printf ("%d",0); - for(inti=top2-1; i>=1; i--) printf ("%d", ans[i]%Ten); thePuts""); + } A return 0; the}
POJ 1392
1#include <cstdio>2#include <cstring>3#include <iostream>4 5 using namespacestd;6 #defineN (1<<16)7 8 intAns[n], cnt[n], stack[n];9 inttop1, TOP2, mod;Ten One voidEulerintVintMoD) A { - while(cnt[v]<2) - { the intw=v*2+Cnt[v]; -cnt[v]++; -stack[top1++]=W; -v=w%MoD; + } - } + A intQ_pow (intAintb) at { - intAns =1; - while(b) - { - if(b&1) Ans *=A; -a*=A; inb>>=1; - } to returnans; + } - the intMain () * { $ //freopen ("In.txt", "R", stdin);Panax Notoginseng intn,k; - while(SCANF ("%d%d", &n, &k), n| |k) the { +Top1=top2=0; Amemset (CNT,0,sizeof(CNT)); thestack[top1++] =0; +MoD = Q_pow (2, N-1); - while(TOP1) $ { $ans[top2++] = stack[--TOP1]; - intv=stack[top1]/2; - Euler (v, MoD); the } - intindex = top2-k-1;Wuyiprintf"%d\n", Ans[index]); the } - return 0; Wu}
POJ 1780, POJ 1392 Euro-pull circuit to find the connected digital string