Originally wanted to practice the euro-pull circuit, the results of the purple book that the problem is a flood problem!!!!!
Test instructions: Given n words, whether the word can be arranged as the first letter of each word and the last letter of the previous word
Solution: Euler channel exists = Basemap Unicom + perceive! = The point of entry is at most only two (in points and out points, respectively)
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <algorithm>5#include <cstring>6#include <cstdlib>7#include <queue>8#include <vector>9#include <map>Ten#include <stack> One#include <string> A - using namespacestd; - the intT,n; - int inch[ -], out[ -]; - intf[ -]; - Chars[1007]; + - intGfintx) { + if(X==f[x])returnF[x]; Af[x]=GF (f[x]); at returnF[x]; - } - - BOOLsolve () { -Memsetinch,0,sizeof(inch)); -Memset out,0,sizeof( out)); in for(intI=0;i< -; i++){ -f[i]=i; to } +scanf"%d",&n); - for(intI=0; i<n;i++){ thescanf"%s", s); * intF1=GF (s[0]-'a'); $ intF2=GF (S[strlen (s)-1]-'a');Panax Notoginseng if(f1!=F2) { -f[f1]=F2; the } + inch[s[0]-'a']++; A out[S[strlen (s)-1]-'a']++; the } + intpre=-1; - for(intI=0;i< -; i++){ $ if(inch[i]!=0|| out[i]!=0){ $ if(pre==-1) -Pre=GF (i); - Else{ the if(PRE!=GF (i))return false; -Pre=GF (i);Wuyi } the } - } Wu for(intI=0;i< -; i++){ - inch[i]=inch[i]- out[i]; About } $Sortinch,inch+ -); - for(intI=1;i< -; i++)if(inch[i]!=0)return false; - if(ABS (inch[0]) >1|| Absinch[ -]) >1||inch[0]+inch[ -]!=0)return false; - if(inch[0]+inch[ -]!=0)return false; A return true; + } the - intMain () { $scanf"%d",&T); the for(intcas=1; cas<=t;cas++){ the if(Solve ()) theprintf"Ordering is possible.\n"); the Else -printf"The door cannot be opened.\n"); in } the return 0; the } About /* the 3 the 2 the ACM + IBM - 3 the ACMBayi Malform the Mouse the 2 - OK - OK the */
UVA 10129 POJ 1386 HDU 1116 Zoj play on words