题目链接: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:

  1. Always shut open doors behind you immediately after passing through
  2. Never open a closed door
  3. 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 欧拉回路的更多相关文章

  1. POJ 1300 Door Man(欧拉回路的判定)

    题目链接 题意 : 庄园有很多房间,编号从0到n-1,能否找到一条路径经过所有开着的门,并且使得通过门之后就把门关上,关上的再也不打开,最后能回到编号为0的房间. 思路 : 这就是一个赤裸裸的判断欧拉 ...

  2. [欧拉回路] poj 1300 Door Man

    题目链接: http://poj.org/problem?id=1300 Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  3. POJ 1300 欧拉通路&欧拉回路

    系统的学习一遍图论!从这篇博客开始! 先介绍一些概念. 无向图: G为连通的无向图,称经过G的每条边一次并且仅一次的路径为欧拉通路. 如果欧拉通路是回路(起点和终点相同),则称此回路为欧拉回路. 具有 ...

  4. POJ 1300 最基础的欧拉回路问题

    题目大意: 从0~n-1编号的房间,从一个起点开始最后到达0号房间,每经过一扇门就关上,问最后能否通过所有门且到达0号房间 我觉得这道题的输入输出格式是我第一次遇到,所以在sscanf上也看了很久 每 ...

  5. poj 1300 欧拉图

    http://poj.org/problem?id=1300 要不是书上有翻译我估计要卡死,,,首先这是一个连通图,鬼知道是那句话表示出来的,终点必须是0,统计一下每个点的度数,如果是欧拉回路那么起点 ...

  6. POJ 1300.Door Man 欧拉通路

    Door Man Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2596   Accepted: 1046 Descript ...

  7. POJ 1780 Code(欧拉回路+非递归dfs)

    http://poj.org/problem?id=1780 题意:有个保险箱子是n位数字编码,当正确输入最后一位编码后就会打开(即输入任意多的数字只有最后n位数字有效)……要选择一个好的数字序列,最 ...

  8. poj 2337 && zoj 1919 欧拉回路+连通性判断

    题目要求按字典序排列,而且可能有重边 所以一开始就将数组从大到小排列,那么我将字符串加入链表时就会令小的不断前移,大的被挤到后面 这里有一点问题就是我一开始使用的是qsort: int cmp(con ...

  9. POJ 1637 混合图欧拉回路

    先来复习一下混合图欧拉回路:给定一张含有单向边和双向边的图,使得每一点的入度出度相同. 首先对于有向边来说,它能贡献的入度出度是确定的,我们不予考虑.对于无向图,它可以通过改变方向来改变两端点的出入度 ...

随机推荐

  1. 5.21_启程日本二面_1 vs 1

    昨天上午刚群面完,晚上7点左右就接到了电话.面试官就两位菇凉,看来她们也是很辛苦.今天下午3点 1 vs 1,在一家咖啡店里,主要是询问下去日本的意愿是否足够强烈.太老实,这里实话实说,也没有表现出非 ...

  2. 小菜的系统框架界面设计-数据的完美呈现(DataGridView扩展)

    背景 今天在做系统报表的过程中,我想实现批量操作DataGridView中的数据,在列中加复选框,通过一个事件触发进行全选或取消,可是在外面添加按钮,这种模式虽然能够实现,但是从系统界面设计的角度,美 ...

  3. php 获取文件后缀名

    $file_ext = strtolower(substr(strrchr($upload_file, '.'), 1)); strrchr:查找指定字符在字符串中的最后一次出现 string str ...

  4. C# 调用系统API 内核 简单样例

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.R ...

  5. c# equals和==的区别

    简言之: equals必须是类型和值都得相等 == 只要值相等 注意: void Main() { ; ; Console.WriteLine(a.Equals(b)); //True (short会 ...

  6. 信驰达携“Zigbee Light Link灯控方案”亮相第18届广州国际照明展

    2013年6月9日至12日,第18届广州国际照明展览会在琶洲中国进出口商品交易会展馆举行,作为全球照明及LED行业风向标和晴雨表,本次展会吸引了来自27个国际及地区,共2600多家企业参展.我公司受T ...

  7. [terry笔记]ArchiveLog归档日志激增解决思路

    归档日志激增的危害是巨大的,最严重的结果就是数据库无法正常工作,导致整个系统无法正常工作,其次就算数据库可以正常工作,但激增的归档会对磁盘产生大量消耗,导致性能下降.       归档日志激增一般是因 ...

  8. Html5 Canvas一个简单的画笔例子

    相比了下Qt quick的canvas和HTML5的canvas,发现HTML5 Canvas在同样绘制绘制操作下性能比Qt的canvas强很多,附上一个HTML5 canvas画笔一例子 var D ...

  9. WPF:将HTML RGB颜色值转化为Color对象的两种方式

    (1)方式一: Color color1 = (Color)System.Windows.Media.ColorConverter.ConvertFromString("#E0E0E0&qu ...

  10. C语言实现冒泡排序法和选择排序法代码参考

    为了易用,我编写排序函数,这和直接在主调函数中用是差不多的. 我认为选择排序法更好理解!请注意 i 和 j ,在写代码时别弄错了,不然很难找到错误! 冒泡排序法 void sort(int * ar, ...