poj 1300 Door Man 欧拉回路
题目链接:http://poj.org/problem?id=1300
You are a butler in a large mansion. This mansion has so many rooms that they are merely referred to by number (room 0, 1, 2, 3, etc...). Your master is a particularly absent-minded lout and continually leaves doors open throughout a particular floor of the house. Over the years, you have mastered the art of traveling in a single path through the sloppy rooms and closing the doors behind you. Your biggest problem is determining whether it is possible to find a path through the sloppy rooms where you:
- 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.
题意:给出一些房间和房间上的门以及房间之间的路径,如果你沿着这条路走到另一个房间,那么就得关掉这条路上的门,关掉的门不能再打开,问能不能从0号房间,在关掉所有门之后刚好走到房间m。
解法:欧拉回路的判断。
无向图的欧拉回路:连通无向图中没有度数为奇数个的节点或者有且仅有两个奇数个节点(此时这两个节点必须一个为起点,另一个为终点)。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#define inf 0x7fffffff
using namespace std;
const int maxn=; int m,n,degree[maxn];
char str[maxn],s[maxn]; int main()
{
while (scanf("%s",str)!=EOF)
{
if (strcmp(str,"ENDOFINPUT")==) break;
scanf("%d%d",&m,&n);
int a;
memset(degree,,sizeof(degree));
memset(s,,sizeof(s));
int cnt=;
getchar();
for (int i= ;i<n ;i++)
{
gets(s);
int len=strlen(s);
if (len==) continue;
a=;
int q=;
for (q= ;q<len ;q++) if (s[q]!=' ') break;
for (int j=q ;j<len ;j++)
{
if (s[j]==' ')
{
degree[i] ++ ;
degree[a] ++ ;
cnt ++ ;
a=;continue;
}
a=a*+s[j]-'';
if (j==len-)
{
degree[i] ++ ;
degree[a] ++ ;
cnt ++ ;
}
}
}
scanf("%s",str);
a=;
int k=-,k2=-;
for (int i= ;i<n ;i++)
{
if (degree[i]%)
{
a++;
if (k==-) k=i;
else k2=i;
}
}
if (a> || a==) printf("NO\n");
else if (a==)
{
if ((k== && k2==m)||(k==m && k2==)) printf("YES %d\n",cnt);
else printf("NO\n");
}
else if (m==) printf("YES %d\n",cnt);
else printf("NO\n");
}
return ;
}
poj 1300 Door Man 欧拉回路的更多相关文章
- POJ 1300 Door Man(欧拉回路的判定)
题目链接 题意 : 庄园有很多房间,编号从0到n-1,能否找到一条路径经过所有开着的门,并且使得通过门之后就把门关上,关上的再也不打开,最后能回到编号为0的房间. 思路 : 这就是一个赤裸裸的判断欧拉 ...
- [欧拉回路] poj 1300 Door Man
题目链接: http://poj.org/problem?id=1300 Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ 1300 欧拉通路&欧拉回路
系统的学习一遍图论!从这篇博客开始! 先介绍一些概念. 无向图: G为连通的无向图,称经过G的每条边一次并且仅一次的路径为欧拉通路. 如果欧拉通路是回路(起点和终点相同),则称此回路为欧拉回路. 具有 ...
- POJ 1300 最基础的欧拉回路问题
题目大意: 从0~n-1编号的房间,从一个起点开始最后到达0号房间,每经过一扇门就关上,问最后能否通过所有门且到达0号房间 我觉得这道题的输入输出格式是我第一次遇到,所以在sscanf上也看了很久 每 ...
- poj 1300 欧拉图
http://poj.org/problem?id=1300 要不是书上有翻译我估计要卡死,,,首先这是一个连通图,鬼知道是那句话表示出来的,终点必须是0,统计一下每个点的度数,如果是欧拉回路那么起点 ...
- POJ 1300.Door Man 欧拉通路
Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2596 Accepted: 1046 Descript ...
- POJ 1780 Code(欧拉回路+非递归dfs)
http://poj.org/problem?id=1780 题意:有个保险箱子是n位数字编码,当正确输入最后一位编码后就会打开(即输入任意多的数字只有最后n位数字有效)……要选择一个好的数字序列,最 ...
- poj 2337 && zoj 1919 欧拉回路+连通性判断
题目要求按字典序排列,而且可能有重边 所以一开始就将数组从大到小排列,那么我将字符串加入链表时就会令小的不断前移,大的被挤到后面 这里有一点问题就是我一开始使用的是qsort: int cmp(con ...
- POJ 1637 混合图欧拉回路
先来复习一下混合图欧拉回路:给定一张含有单向边和双向边的图,使得每一点的入度出度相同. 首先对于有向边来说,它能贡献的入度出度是确定的,我们不予考虑.对于无向图,它可以通过改变方向来改变两端点的出入度 ...
随机推荐
- JavaService应用中的注意事项
最近有个技术需求,要把已写好的Java程序注册成Windows服务,网上搜了两个快捷办法,一个是Java Service Wrapper,这是个收费的第三方组件,免费的版本还没有适合64位Win7系统 ...
- Nginx下10个安全问题提示
Nginx是当今最流行的Web服务器之一.它为世界上7%的web流量提供服务而且正在以惊人的速度增长.它是个让人惊奇的服务器,我愿意部署它 下面是一个常见安全陷阱和解决方案的列表,它可以辅助来确保你的 ...
- PHP变量名区分大小写,函数名不区分大小写
PHP变量名区分大小写,函数名不区分大小写,经常被新手忽视的小细节,测试如下. PHP变量名区分大小写测试: <?php $aaa = "phpddt.com"; $AAA ...
- mysql中character_set_connection的作用
character_set_client = x character_set_results = xcharacter_set_connection = x; 我们常用在mysql操作类中使用这三面, ...
- 简单Spinner
mainActivity package com.zzw.spinner; import android.app.Activity; import android.content.Context; i ...
- Index of my articles
65:一个表格说明RelativeLayout中的几个重要属性[Written By KillerLegend] (2013-10-16 21:59) 64:win7修改软件[授权给…]后面的名称 ( ...
- devexpress 控制面板汉化方式 参考信息
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- jQuery学习笔记(2)
val() 当鼠标放上去的时候,文本消失,鼠标拿开,文本恢复 效果图: code as below: <html xmlns="http://www.w3.org/1999/xhtml ...
- virtualenv 安装
virtualenv 是一个创建隔离的Python环境的工具. virtualenv要解决的根本问题是库的版本和依赖,以及权限问题.假设你有一个程序,需要LibFoo的版本1,而另一个程序需要版本2, ...
- 对 cloudwu 简单的 cstring 进行简单解析
题外话 以前也用C写过字符串,主要应用的领域是,大字符串,文件读取方面.写的很粗暴,用的凑合着.那时候看见云风前辈的一个开源的 cstring 串. 当时简单观摩了一下,觉得挺好的.也没细看.过了较长 ...