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 混合图欧拉回路
先来复习一下混合图欧拉回路:给定一张含有单向边和双向边的图,使得每一点的入度出度相同. 首先对于有向边来说,它能贡献的入度出度是确定的,我们不予考虑.对于无向图,它可以通过改变方向来改变两端点的出入度 ...
随机推荐
- Ado.net利用反射执行SQL得到实体
public Model.orderParent GetTraceIDforID(string orderid) { string sql = string.Format(" select ...
- Hadoop在win7下部署的问题
问题: 为了测试方便所以在win7下部署了伪分布式hadoop运行环境,但是部署结束后在命令行运行hadoop命令创建一个用户文件目录时出现了一下情况: 系统找不到指定的批标签- make_comma ...
- javascript回车完美实现tab切换功能
javascript通过回车实现tab切换功能,最经有一个项目是给化工厂做的在使用的过程中需要输入大量的数据,使用的都是小键盘区,在以前都是通过excel录入数据的现在, 在网页上需要实现excel ...
- recurse_array_change_key_case()递规返回字符串键名全为小写或大写的数组
//递归返回字符串键名全为小写或大写的数组function recurse_array_change_key_case(&$input, $case = CASE_LOWER){ if( ...
- ORMLiteDatabase的简单使用并且与其他的表相互联系
1.下载jar 具体到Android,需要在 http://ormlite.com/releases 页面下载两个jar 包(本文基于ORMLite的版本是:ormlite 4.49-SNAPSHOT ...
- 【转】在delphi中实现控件的拖拽
提示:可以添加一个布尔来控制可否拖动的状态,这里提供所有都能拖动的方法. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseB ...
- 基于Memcached的Session共享问题
把Memcached的key(Guid)写入浏览器的cookie(类比SessionId) 存值: string sessionId = Guid.NewGuid().ToString(); Comm ...
- USB设备驱动
在Linux 内核中,使用usb_driver 结构体描述一个USB 设备驱动,usb_driver 结构体的定义如代码清单20.11 所示.代码清单20.11 usb_driver 结构体 stru ...
- 第三节:卸载AppDomain
AppDomain很出色的一个能力就是它允许卸载.卸载AppDomain会导致CLR卸载AppDomain中的所有程序集.还会释放AppDomain的Loader堆.为了卸载一个AppDomain,可 ...
- pyenv
export PYTHON_BUILD_MIRROR_URL="http://pyenv.qiniudn.com/pythons/"