Test instructions
Give a few words, and ask if you can use all the word idioms solitaire
Analytical:
Consider the first and the end letters of each word as two points U and V respectively, after entering each word, U's out of the degree + +, v in degrees + +
Finally determine whether or not to form a Euler path or the Euler circuit, of course, first of all to determine whether it is a connected block, with and check set maintenance is good, of course, there is self-ring, so with a vis to mark whether this point has occurred
Look at the code, you know.
#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 =10010, INF =0x7fffffff, Ll_inf =0x7fffffffffffffff;intHEAD[MAXN],inch[MAXN], out[MAXN], F[MAXN], VIS[MAXN];intN, M, CNT;Set<int>s;intFindintx) { returnF[X] = = x? x: (F[x] =find (F[x]));}intMain () {intT; CIN>>T; while(t--) {s.clear (); MEM (inch,0); MEM ( out,0); Mem (Vis,0); for(inti =1; I <= -; i++) F[i] =i; stringstr; CIN>>N; for(inti =1; I <= N; i++) {cin>>str; intU = str[0] -'a'+1; intv = str[str.size ()-1] -'a'+1; intL =find (U); intR =Find (v); Vis[u]= Vis[v] =1; if(l! = r) F[l] =R; out[u]++; inch[v]++; } intCnt1 =0, Cnt2 =0, flag =0, cnt =0; for(inti =1; I <= -; i++) { intx =find (i); if(Vis[x]) S.insert (x); if(inch[i]! = out[i]) flag=1, cnt++; if(inch[I] = = out[I] +1) Cnt1++; Else if(inch[I] +1== out[i]) Cnt2++; } if(S.size ()! =1) {cout<<"The door cannot be opened."<<Endl; Continue; } if(CNT! =2&& cnt! =0) {cout<<"The door cannot be opened."<<Endl; Continue; } if(Cnt1 = =1&& Cnt2 = =1|| Flag = =0) cout<<"ordering is possible."<<Endl; Elsecout<<"The door cannot be opened."<<Endl; } return 0;}
Play on Words HDU-1116 (Euler's Road judgment + and check set)