uva 10596 - Morning Walk

点击打开链接

题目意思:给定n个点,判断由某一点出发最后能否回到原点

解题思路:比较简单的欧拉回路的应用,根据欧拉回路的性质,所有节点的度数(入度加出度)都是偶数,我么只须要开一个road数组存储每一个节点的度数,最后遍历数组判断是不是全部都是偶数即可  

代码:

//简单的欧拉回路的应用
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
const int MAXN = 210;

int  n , r;
int  road[MAXN];//存储节点的度数

int main(){
    int x , y , i , j , mark;
    while(~scanf("%d%d" , &n , &r)){
        memset(road , 0 , sizeof(road));
        mark = 0;
        for(i = 0 ; i < r ; i++){
            scanf("%d%d" , &x , &y);
            road[x]++;
            road[y]++;
        }
        if(r != 0){
            for(j = 0 ; j < n ; j++){
                if(road[j] %2 != 0){
                    mark = 0;
                    break;
                }
            }
            if(j == n)
                mark = 1;
        }
        if(mark)
            printf("Possible\n");
        if(mark == 0)
            printf("Not Possible\n");
    }
    return 0 ;
}
时间: 2024-11-01 21:25:40

uva 10596 - Morning Walk的相关文章

UVa 10596:Morning Walk, 赤裸裸的欧拉回路

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=105&page=show_problem&problem=1537 题目类型: 欧拉回路, 并查集, dfs 题目: Kamal is a Motashota guy. He has got a new job in Chittagong. So, he has moved to Chittagong fr

UVa 10714:Ants

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1655 原题: An army of ants walk on a horizontal pole of length l cm, each with a constant speed of 1 cm/s. When a walking ant rea

UVa 10110 Light, more light:数论

10110 - Light, more light Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1051 The Problem There is man named "mabu" for switching on-off light

UVa 10161 Ant on a Chessboard:简单数学

10161 - Ant on a Chessboard Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=1102 Background One day, an ant called Alice came to an M*M chessboard. She wa

UVa 10602

链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=1543 类型:贪心 原题: Company Macrohard has released it's new version of editor Nottoobad, which can understand a few voice commands.

UVa 10392 Factoring Large Numbers:素因子分解

10392 - Factoring Large Numbers Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=100&page=show_problem&problem=1333 One of the central ideas behind much cryptography is that factoring

UVa 10182 Bee Maja:规律&amp;amp;O(1)算法

10182 - Bee Maja Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1123 Maja is a bee. She lives in a bee hive with thousands of other bees. This bee hive c

算法题之UVA 763

Fibinary Numbers The standard interpretation of the binary number 1010 is 8 + 2 = 10. An alternate way to view the sequence ``1010'' is to use Fibonacci numbers as bases instead of powers of two. For this problem, the terms of the Fibonacci sequence

算法题:UVa 11461 Square Numbers (简单数学)

11461 - Square Numbers Time limit: 1.000 seconds http://uva.onlinejudge.org/index.php? option=com_onlinejudge&Itemid=8&category=467&page=show_problem&problem=24 56 A square number is an integer number whose square root is also an integer.