Door Mans
| Time Limit: 1000MS |
|
Memory Limit: 10000K |
| Total Submissions: 2639 |
|
Accepted: 1071 |
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:
- Always shut open doors behind-immediately after passing through
- Never open a closed door
- 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:
- 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).
- 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!
- 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
The question of "analysis" is the decision of a Euler's circuit, very simple, but the input is a bit cumbersome.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<climits>#include<cstring>#include<string>#include<Set>#include<map>#include<queue>#include<stack>#include<vector>#include<list>#include<functional>#defineMoD 1000000007#defineINF 0x3f3f3f3f#definePi ACOs (-1.0)using namespaceStd;typedefLong Longll;Const intn=1005;Const intm=150005; ll Power (ll A,intB,ll c) {ll ans=1; while(b) {if(b%2==1) {ans= (ans*a)%c;b--;} B/=2; a=a*a%c;}returnans;}CharStr[n];intn,m,cnt[ *];intMain () { while(Gets (str)! =NULL) { if(!STRCMP (str,"Endofinput")) Break; SSCANF (str,"%*s%d%d",&m,&N); memset (CNT,0,sizeof(CNT)); intans=0; for(intI=0; i<n;i++) {gets (str); intk=0, J; while(Sscanf (Str+k,"%d", &j) = =1) {ans++; Cnt[i]++; CNT[J]++; while(str[k]&&str[k]==' ') k++; while(str[k]&&str[k]!=' ') k++; }} gets (str); intOdd=0, even=0; for(intI=0; i<n;i++){ if(cnt[i]&1) odd++; Elseeven++; } if(!odd&&!m) printf ("YES%d\n", ans); Else if(odd==2&& (cnt[m]&1) && (cnt[0]&1) &&m) printf ("YES%d\n", ans); Elseprintf"no\n"); } return 0;}View Code
Poj1300door Man (Euler circuit)