HDU 1116 play on words

Source: Internet
Author: User

Problem address: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1116

 

A question about Euler's loop. I have just been in contact with oocl, so I have collected some information:

Definition of European Union:

If such a path exists in graph G so that it passes through every edge of graph G once, the path is called Euler's path. If the path is a circle, it is called Euler's (Euler) loop. An image with an Euler's path is called a map E ).

Methods to determine whether there is Euler's path:

Directed Graph: Graph connectivity. There is a vertex degree of exit greater than 1, there is a vertex degree of entry greater than 1, and the rest are degrees of exit = inbound.

Undirected graph: Graph connectivity. Only two vertices are odd, and the rest are even.

Methods To determine whether the Euler loop exists:

Directed Graph: Graph connectivity. All vertices are outdegree = inbound.

Undirected graph: Graph connectivity. All vertices are even. Reference: http://www.cnblogs.com/buptLizer/archive/2012/04/15/2450297.html http://www.cnblogs.com/zhourongqing/archive/2012/07/10/2585235.html
# Include <iostream> # include <cstring> # include <string> # include <cstdio> # include <queue> using namespace STD; const int maxn = 30; int in [maxn]; // corresponding to the inbound int out [maxn]; // corresponding to the outbound int used [maxn]; bool vis [maxn]; int find (int n) {If (n! = Used [N]) used [N] = find (used [N]); Return used [N];} void Merge (int A, int B) {// merge int x = find (a); int y = find (B); If (X! = Y) used [y] = x; return;} int main () {int t, n; int I, Pos; int injudge, outjudge; bool bug; string temp; cin> T; while (t --) {CIN> N; for (I = 0; I <maxn; I ++) used [I] = I; memset (in, 0, sizeof (in); memset (Out, 0, sizeof (out); memset (VIS, false, sizeof (VIS )); // initialize while (n --) {CIN> temp; Pos = temp. length ()-1; out [temp [0]-'a'] ++; in [temp [POS]-'a'] ++; merge (temp [0]-'A', temp [POS]-' A'); vis [temp [0]-'a'] = vis [temp [POS]-'a'] = true;} int counter = 0; // used to determine whether there are several graphs. If there are more than one graph, it cannot meet the question requirements for (I = 0; I <= 'Z'-'A'; I ++) if (vis [I] & amp; used [I] = I) Counter ++; If (counter> 1) {cout <"The door cannot be opened. \ n "; continue;} injudge = outjudge = 0; bug = false; for (I = 0; I <= 'Z'-'A'; I ++) if (vis [I]) {If (in [I] = out [I]) continue; else if (in [I]-out [I] = 1) injudge ++; // The number of incoming values greater than the outgoing value. 1 e LSE if (out [I]-in [I] = 1) outjudge ++; // Number of outgoing records greater than inbound: 1 else bug = true ;} if (Bug) {cout <"The door cannot be opened. \ n "; continue;} If (injudge = 1 & outjudge = 1) {cout <" ordering is possible. \ n "; continue;} If (! Injudge &&! Outjudge) {cout <"ordering is possible. \ n"; continue;} cout <"The door cannot be opened. \ n";} return 0 ;}

 

 

HDU 1116 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.