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 混合图欧拉回路
先来复习一下混合图欧拉回路:给定一张含有单向边和双向边的图,使得每一点的入度出度相同. 首先对于有向边来说,它能贡献的入度出度是确定的,我们不予考虑.对于无向图,它可以通过改变方向来改变两端点的出入度 ...
随机推荐
- Linux基础知识-文件管理
Linux目录与路径 cd:切换目录 例如:cd ~willhua,则回到用户willhua的主文件夹 cd ~或者cd,则表示回到自己的的主文件夹 cd -,则表示回到上个目录 pwd:显示目前 ...
- android 分段显示文本颜色控件
效果: 使用: <com.bei.myapplication.app.ProgressTextView xmlns:ptv="http://schemas.android.com/ap ...
- php简单缓存类
<?phpclass Cache { private $cache_path;//path for the cache private $cache_expire;//seconds ...
- php抓取post方式提交的页面
function curlBy($url, $data=array()) { $ch = curl_init(); if(!empty($data)){ ...
- Android开发之Source无法覆写public void onClick(View v)
初学Android开发,在为一个按钮[该按钮继承OnClickListener()]写监听时,发现无法在Source中引入public void onClick(View v),当时非常纳闷,平常情况 ...
- Python脚本控制的WebDriver 常用操作 <八> 简单的对象定位
这一部分的内容,将是在WebDriver中,定位元素方法的演示,是将Selenium中Selenese元素定位命令的WebDriver中使用方法的结合 Selenium中元素定位方法复习可以参考: & ...
- 关于datagridview的一些操作
1.绑定datatable时,会显示出不需要显示的列可以加datagridview.AutoGenerateColumns = false; 2.如果datagridview的某列是数值型的,有小数, ...
- About Inside the Azure Storage Outage of November 18th
Channel 9的官方解释 http://channel9.msdn.com/posts/Inside-the-Azure-Storage-Outage-of-November-18th 曾经在自己 ...
- 欢迎来到vmax-tam的博客
欢迎来到vmax-tam的博客 我是一个新手程序员 以后会不断学习 把学到的东西记录下来 和大家一起分享的 谢谢大家指教
- ios中怎么样点击背景退出键盘
//退出键盘 只需一句,药到病除 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self.view endEdi ...