Code POJ-1780 (stack emulation DFS)

Source: Internet
Author: User

Test instructions

is the digital Hamiltonian circuit.

Analytical:

is even ... You can not use DFS directly, you have to manually open the stack to simulate DFS

Emm ... Look at the boss half a day to see smattering

#include <iostream>#include<cstdio>#include<sstream>#include<cstring>#include<map>#include<cctype>#include<Set>#include<vector>#include<stack>#include<queue>#include<algorithm>#include<cmath>#include<bitset>#defineRap (i, A, n) for (int i=a; i<=n; i++)#defineRep (I, A, n) for (int i=a; i<n; i++)#defineLap (I, a, n) for (int i=n; i>=a; i--)#defineLEP (i, A, n) for (int i=n; i>a; i--)#defineRD (a) scanf ("%d", &a)#defineRlld (a) scanf ("%lld", &a)#defineRC (a) scanf ("%c", &a)#defineRS (a) scanf ("%s", a)#definePD (a) printf ("%d\n", a);#definePlld (a) printf ("%lld\n", a);#definePC (a) printf ("%c\n", a);#definePS (a) printf ("%s\n", a);#defineMOD 2018#defineLL Long Long#defineULL unsigned long Long#definePair Pair<int, int>#defineMem (A, B) memset (A, B, sizeof (a))#define_ Ios_base::sync_with_stdio (0), Cin.tie (0)//freopen ("1.txt", "R", stdin);using namespacestd;Const intMAXN = 1e6 +Ten, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;intN, tot, SS;intSTK[MAXN], CNT[MAXN], ANS[MAXN];//The last result of the STK is that CNT is the value of the DFS I of each layer. Ans is the V when each layer is not modulointF[MAXN];voidNo_dfs (intu) {     while(Cnt[u] <Ten)    {        intTMP = u *Ten+Cnt[u]; Cnt[u]++; Ans[tot+ +] = tmp;//Why first record in the modulo? Because what we need is the "side" of every time, and this No_dfs function is to find out the value of Dfs at the same I for all layersu = tmp% f[n-1]; }}intMain () {f[0] =1;  for(inti =1; I <=6; i++) F[i] = f[i-1] *Ten;  while(Cin >> N &&N) {mem (CNT,0); SS= Tot =0; No_dfs (0);  while(tot) {intx = ans[--tot]; Stk[ss+ +] = x%Ten;//the last one, the "side", can be obtained by taking the modelNo_dfs (X/Ten);//equivalent to back to the previous layer in DFS        }         for(inti =0; I < n-1; i++) cout<<"0";  for(inti = SS-1; I >=0; i--) cout<<Stk[i]; cout<<Endl; }    return 0;}

Code POJ-1780 (stack emulation DFS)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.