UVA 10129 POJ 1386 HDU 1116 Zoj play on words

Source: Internet
Author: User

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

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.