Uva10054 Euler circuit
Test instructions: give n beads, each of the two ends of the beads are different colors. Ask whether a necklace can be formed, the two adjacent beads adjacent to the opposite ends of the same color.
Idea: think of color as a point. Beads are seen as edges. Each bead is connected between the two colors. The number of degrees for any point in the no-map is even, and the graph has a Euler loop. You can then use the Euler function to output it.
/*id:onlyazh1lang:c++task:the Necklace*/#include<iostream>#include<cmath>#include<stack>#include<queue>#include<cctype>#include<vector>#include<cstring>#include<fstream>#include<iomanip>#include<algorithm>using namespacestd;typedef unsignedLong Longll;intdeg[ -];intg[ -][ -];voidEulerintu) { for(intI=1; i<= -; i++) if(G[u][i]) {G[u][i]--; g[i][u]--; Euler (i); cout<<i<<" "<<u<<Endl; }}intMain () {//ifstream cin ("In.txt"); intT,n,u,v,icase=0; CIN>>u; while(t--) {memset (deg,0,sizeof(deg)); memset (G,0,sizeof(G)); CIN>>N; while(n--) {cin>>u>>v; G[U][V]++; g[v][u]++; Deg[u]+ +;d eg[v]++; } if(icase) cout<<Endl; cout<<"Case #"<<++icase<<Endl; BOOLflag=true; for(intI=1; i<= -; i++) if(deg[i]%2==1) {cout<<"Some beads may lost"<<Endl; Flag=false; Break; } if(flag) Euler (U); } return 0;}
View Code
Uva10054 the Necklace