POJ 1300.Door Man 欧拉通路
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 2596 | Accepted: 1046 |
Description
- Always shut open doors behind you immediately after passing through
- Never open a closed door
- End up in your chambers (room 0) with all doors closed
In this problem, you are given a list of rooms and open doors between them (along with a starting room). It is not needed to determine a route, only if one is possible.
Input
A single data set has 3 components:
- Start line - A single line, "START M N", where M indicates the butler's starting room, and N indicates the number of rooms in the house (1 <= N <= 20).
- Room list - A series of N lines. Each line lists, for a single room, every open door that leads to a room of higher number. For example, if room 3 had open doors to rooms 1, 5, and 7, the line for room 3 would read "5 7". The first line in the list represents room 0. The second line represents room 1, and so on until the last line, which represents room (N - 1). It is possible for lines to be empty (in particular, the last line will always be empty since it is the highest numbered room). On each line, the adjacent rooms are always listed in ascending order. It is possible for rooms to be connected by multiple doors!
- End line - A single line, "END"
Following the final data set will be a single line, "ENDOFINPUT".
Note that there will be no more than 100 doors in any single data set.
Output
Sample Input
START 1 2
1 END
START 0 5
1 2 2 3 3 4 4 END
START 0 10
1 9
2
3
4
5
6
7
8
9 END
ENDOFINPUT
Sample Output
YES 1
NO
YES 10 题目链接:http://poj.org/problem?id=1300
题意:有很多房间,编号为0,1,2,3,...。输入m,n。m为起始房间号;n为房间总数(1≤n≤20)。接下来n行列出了房间通向其他的房间号。(注意:空行也是输入,表示这个房间通向其他的房间号都已经出现了。)从m开始通过所有的门,通过后把门关上,关上了的门不能打开,最后回到0。 思路:最基础的欧拉通路的判断,判断是否是起点是m,终点是0的欧拉通路(默认是连通图)。主要要注意输入输出的格式。 代码:
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int door[];
char s[];
int Init()
{
int len=;
char ch;
while((ch=getchar())&&ch!='\n')
{
s[len++]=ch;
}
return len;
}
int main()
{
int i,j,m,n;
int len;
int ans=;
while(scanf("%s",s)!=EOF)
{
len=strlen(s);
if(len==) break;
scanf("%d%d",&m,&n);
getchar();
memset(door,,sizeof(door));
ans=;
for(i=; i<n; i++)
{
len=Init();
for(j=; j<len; j++)
{
int num=;
while(j<len&&s[j]!=' ')
{
num=num*+(s[j]-'');
j++;
}
ans++;
door[i]++;
door[num]++;
}
}
scanf("%s",s);
int even=,odd=;
for(i=; i<n; i++)
{
if(door[i]%==) even++;
else odd++;
}
if(odd==&&m==) cout<<"YES "<<ans<<endl;
else if(odd==&&m!=&&door[]%!=&&door[m]%!=) cout<<"YES "<<ans<<endl;
else cout<<"NO"<<endl;
}
return ;
}
POJ 1300.Door Man 欧拉通路的更多相关文章
- POJ 2513 无向欧拉通路+字典树+并查集
题目大意: 有一堆头尾均有颜色的木条,要让它们拼接在一起,拼接处颜色要保证相同,问是否能够实现 这道题我一开始利用map<string,int>来对颜色进行赋值,好进行后面的并查操作以及欧 ...
- POJ 1300 欧拉通路&欧拉回路
系统的学习一遍图论!从这篇博客开始! 先介绍一些概念. 无向图: G为连通的无向图,称经过G的每条边一次并且仅一次的路径为欧拉通路. 如果欧拉通路是回路(起点和终点相同),则称此回路为欧拉回路. 具有 ...
- poj 2513 连接火柴 字典树+欧拉通路 好题
Colored Sticks Time Limit: 5000MS Memory Limit: 128000K Total Submissions: 27134 Accepted: 7186 ...
- Colored Sticks POJ - 2513 并查集+欧拉通路+字典树hash
题意:给出很多很多很多很多个棒子 左右各有颜色(给出的是单词) 相同颜色的可以接在一起,问是否存在一种 方法可以使得所以棒子连在一起 思路:就是一个判欧拉通路的题目,欧拉通路存在:没奇度顶点 或者 ...
- POJ 1386 Play on Words(有向欧拉通路 连通图)
题意 见下方中文翻译 每一个单词能够看成首尾两个字母相连的一条边 然后就是输入m条边 推断是否能构成有向欧拉通路了 有向图存在欧拉通路的充要条件: 1. 有向图的基图连通: 2. 全部点的出度和 ...
- poj2513- Colored Sticks 字典树+欧拉通路判断
题目链接:http://poj.org/problem?id=2513 思路很容易想到就是判断欧拉通路 预处理时用字典树将每个单词和数字对应即可 刚开始在并查集处理的时候出错了 代码: #includ ...
- ACM/ICPC 之 DFS求解欧拉通路路径(POJ2337)
判断是欧拉通路后,DFS简单剪枝求解字典序最小的欧拉通路路径 //Time:16Ms Memory:228K #include<iostream> #include<cstring& ...
- hdu1116有向图判断欧拉通路判断
Play on Words Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 欧拉回路&欧拉通路判断
欧拉回路:图G,若存在一条路,经过G中每条边有且仅有一次,称这条路为欧拉路,如果存在一条回路经过G每条边有且仅有一次, 称这条回路为欧拉回路.具有欧拉回路的图成为欧拉图. 判断欧拉通路是否存在的方法 ...
随机推荐
- ajax 使用 三种方法 设置csrf_token的装饰器
1. CSRF中间件 CSRF跨站请求伪造 2. 补充两个装饰器 from django.views.decorators.csrf import csrf_exempt, csrf_prote ...
- 并发基础(十) 线程局部副本ThreadLocal之正解
本文将介绍ThreadLocal的用法,并且指出大部分人对ThreadLocal 的误区. 先来看一下ThreadLocal的API: 1.构造方法摘要 ThreadLocal(): 创建一个线程 ...
- Executor框架(一)Executor框架介绍
Executor框架简介 Executor框架的两级调度模型 在HotSpot VM的线程模型中,Java线程被一对一映射为本地操作系统线程.Java线程启动时会创建一个本地操作系统线程:当Jav ...
- 内置锁(二)synchronized下的等待通知机制
一.等待/通知机制的简介 线程之间的协作: 为了完成某个任务,线程之间需要进行协作,采取的方式:中断.互斥,以及互斥上面的线程的挂起.唤醒:如:生成者--消费者模式.或者某个动作完成,可以唤醒下一 ...
- Static / Const 的概念
C/C++/Java Static / Const 的概念 这里以C为准,其他语言类似. Static变量是指分配不变(只可分配一次,以后再分配就无效了.)的变量 -- 它的存活寿命或伸展域可以贯穿程 ...
- 最近开始研究php的缓存技术,来个系统自带的OPcache
最近开始研究php的缓存技术,来个系统自带的OPcache php5.5以上版本 系统自带 PHP5.2-5.4 可通过扩展来安装 OPcache是 zend出品 比apc的优势在于 长期更新 ...
- js实现点击按钮弹出上传文件的窗口
转自:https://www.jb51.net/article/100916.htm 1.详细描述 在页面上设置一个“选择文件”按钮,点击该按钮,会弹出本地磁盘信息用于选择文件. 2.代码 ? 1 2 ...
- delphi 泛型 c++builder 泛型
delphi 泛型 System.Generics.Collections.pas TList<T> http://docwiki.embarcadero.com/Libraries/Be ...
- 前端-javascript-ECMAScript5.0
-前端常用开发工具:sublime.visual Studio Code.HBuilder.Webstorm. 使用的PCharm跟WebStorm是JetBrains公司推出的编辑工具,开发阶段建议 ...
- How to Pronounce Ending T Clusters + Homophones — Baking!
How to Pronounce Ending T Clusters + Homophones — Baking! Share Tweet Share Tagged With: ARE Reducti ...