Morning Walk UVA 10596

本文探讨了一道关于欧拉图的编程题,通过分析和给出代码实现,介绍了有向图和无向图中欧拉路径的判定方法。

Problem H

Morning Walk

Time Limit

3 Seconds

Kamalis aMotashotaguy. He has got a new job inChittagong. So, he has moved toChittagongfromDinajpur. He was getting fatter inDinajpuras he had no work in his hand there. So, moving toChittagonghas turned to be a blessing for him. Every morning he takes a walk through the hilly roads of charming cityChittagong. He is enjoying this city very much. There are so many roads inChittagongand every morning he takes different paths for his walking. But while choosing a path he makes sure he does not visit a road twice not even in his way back home. An intersection point of a road is not considered as the part of the road. In a sunny morning, he was thinking about how it would be if he could visit all the roads of the city in a single walk. Your task is to helpKamalin determining whether it is possible for him or not.

Input

Input will consist of several test cases. Each test case will start with a line containing two numbers. The first number indicates the number of road intersections and is denoted byN(2 ≤ N ≤ 200). The road intersections are assumed to be numbered from0toN-1. The second numberRdenotes the number of roads (0 ≤ R ≤ 10000). Then there will beRlines each containing two numbersc1andc2indicating the intersections connecting a road.

Output

Print a single line containing the text “Possible” without quotes if it is possible forKamalto visit all the roads exactly once in a single walk otherwise print “Not Possible”.

Sample Input

Output for Sample Input

22

0 1

1 0

2 1

0 1

Possible

Not Possible

Problemsetter: Muhammad Abul Hasan

International Islamic UniversityChittagong



这道题一看觉得是挺简单的欧拉图问题,一想总觉得不对劲,果然卡了很久,对欧拉图一点都不熟悉,代码还参考了别人的,在这里写一下欧拉图的判断

有向图欧拉路或欧拉回路的判定方法:
(1)有向图G为欧拉图(存在欧拉回路),当且仅当G的基图连通,且所有顶点的入度等于出度。
(2)有向图G为半欧拉图(存在欧拉道路),当且仅当G的基图连通,且存在顶点u的入度比出度大1、v的入度比出度小1,其它所有顶点的入度等于出度。

无向图的欧拉图判定方法:

(1) 图连通。

(2)所有的点的度数(出度和入度之和)为偶数。

#include<iostream>
#include<cstring>

using namespace std;

int du[210];
int bin[210];

int findx(int t)
{
    int r=t;
    while(bin[r]!=r)
    {
        r=bin[r];
    }
    return r;
}

void mergex(int x,int y)
{
    int fx,fy;
    fx=findx(x),fy=findx(y);
    if(fx!=fy)
    {
        bin[fx]=fy;
    }
}

int main()
{
    int n,r;
    while(cin>>n>>r)
    {
        if(r==0)
        {
            cout<<"Not Possible"<<endl;
            continue;
        }
        memset(du,0,sizeof(du));
        int i,j,k;
        for(i=0;i<n;i++)
            bin[i]=i;
        for(i=0;i<r;i++)
        {
            cin>>j>>k;
            du[j]++;
            du[k]++;
            mergex(j,k);
        }
        int tag=1,t=0;
        for(i=0;i<n;i++)
            if(bin[i]==i) t++;
        for(i=0;i<n;i++)
        {
            if((du[i])%2!=0)
            {
                tag=0;
                break;
            }
        }
        if(tag&&t==1) cout<<"Possible"<<endl;
        else cout<<"Not Possible"<<endl;
    }
    return 0;
}


【无线传感器】使用 MATLAB和 XBee连续监控温度传感器无线网络研究(Matlab代码实现)内容概要:本文围绕使用MATLAB和XBee技术实现温度传感器无线网络的连续监控展开研究,介绍了如何构建无线传感网络系统,并利用MATLAB进行数据采集、处理与可视化分析。系统通过XBee模块实现传感器节点间的无线通信,实时传输温度数据至主机,MATLAB负责接收并处理数据,实现对环境温度的动态监测。文中详细阐述了硬件连接、通信协议配置、数据解析及软件编程实现过程,并提供了完整的MATLAB代码示例,便于读者复现和应用。该方案具有良好的扩展性和实用性,适用于远程环境监测场景。; 适合人群:具备一定MATLAB编程基础和无线通信基础知识的高校学生、科研人员及工程技术人员,尤其适合从事物联网、传感器网络相关项目开发的初学者与中级开发者。; 使用场景及目标:①实现基于XBee的无线温度传感网络搭建;②掌握MATLAB与无线模块的数据通信方法;③完成实时数据采集、处理与可视化;④为环境监测、工业测控等实际应用场景提供技术参考。; 阅读建议:建议读者结合文中提供的MATLAB代码与硬件连接图进行实践操作,先从简单的点对点通信入手,逐步扩展到多节点网络,同时可进一步探索数据滤波、异常检测、远程报警等功能的集成。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值