POJ 1300 Door Man (Euler loop _ format control *)

Source: Internet
Author: User
Tags in degrees

Description

You is a butler in a large mansion. This mansion have so many rooms that they is merely referred to by number (0, 1, 2, 3, etc ...). Your Master is a particularly absent-minded lout and continually leaves doors open throughout a particular floor of the Ho Use. Over the years, you had mastered the art of traveling in a single path through the sloppy rooms and closing the doors beh IND you. Your biggest problem is determining whether it's possible to find a path through the sloppy rooms where you:

    1. Always shut open doors behind-immediately after passing through
    2. Never open a closed door
    3. End up in your chambers (guest 0) with all doors closed

In this problem, you is given a list of rooms and open doors between them (along with a starting). It is not needed to determine a route, only if one is possible.

Input

Input to this problem would consist of a (Non-empty) series of up to data sets. Each data set is formatted according to the following description, and there would be no blank lines separating data s Ets.
A Single Data set have 3 components:

    1. Start Line-a single line, "Start M N", where m indicates the Butler ' s starting, and N indicates the number of rooms In the House (1 <= N <= 20).
    2. The List-a series of N lines. Each line lists, the for a single, every open door the leads to a, the higher number. For example, if the box 3 had open doors to rooms 1, 5, and 7, the line for box 3 would read "5 7". The first line in the list represents 0. The second line represents guest 1, and so on until the last line, which represents (N-1). It's possible for lines to being empty (in particular, the last line would always be empty since it's the highest numbered R OOM). On all line, the adjacent rooms is always listed in ascending order. It's possible for rooms to being connected by multiple doors!
    3. End Line-a single line, "End"

Following the final data set would be a, "endofinput".

Note that there'll be is no more than the doors in any single data set.

Output

For each data set, there'll is exactly one line of output. If It is a possible for the butler (by following the "rules in the introduction") to walk into his chambers and close the FINA L Open door behind him, print a line "YES X", where X is the number of the doors he closed. Otherwise, print "NO".

Sample Input

START 1 21ENDSTART 0 2 2 3 3 4 4ENDSTART 0 101 923456789ENDENDOFINPUT

Sample Output

YES 1NOYES 10



Looks like the main test is the input and output ...

Because the improper handling of the carriage return after start M N causes wa*n, it seems that scanf ("%d%d\n", &a,&b) is useless anyway. or direct GetChar () good.

Euler circuit Small problem

1. Determine whether the degree of all sides is an even number, and the starting point is 0 (because the last to return to 0 points), there is Euler circuit

2. If the starting point m and 0 points are odd in degrees and M is not 0, then there is Euler pathway


Get new skills, a new input method. The following code is attached \ \

#include <iostream> #include <cstring> #include <sstream> #include <cstdio>using namespace std; int main () {string Buf;stringstream stream;int i,j,n,m;int deg[30];cin>>buf;while (buf!= "Endofinput") {int side=0 ; memset (deg,0,sizeof (deg)); Cin>>m>>n;getchar (); for (i=0;i<n;i++) {int tem;getline (CIN,BUF); stream <<buf;while (stream>>tem) {side++;d eg[i]++;d eg[tem]++;} Stream.clear ();} Cin>>buf;int even=0;int odd=0;for (i=0;i<n;i++) {if (deg[i]%2) Odd++;else even++;} if (Odd==0 && m==0) printf ("Yes%d\n", side), else if (odd==2 && deg[0]%2 && deg[m]%2 && m!=0) printf ("Yes%d\n", side); else printf ("no\n"); Cin>>buf;}}




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 1300 Door Man (Euler loop _ format control *)

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.