uva 10968 - KuPellaKeS

本文介绍了一种使用图论和最短路径算法解决古代城市道路结构问题的方法,旨在找到破坏最少道路数量使每个城市拥有偶数邻居。

KuPellaKes

In ancient times, many territories were under the control of a powerful king called Basm. Basm is well-known in history because of his strange works and as a result, there are many history-lovers who wish to know more about him. Koorosh is one of them and he has worked hard to find a way to know more about Basm’s works.

Recently, he managed to invent a Time Machine™ and traveled to the past to Basm time in order to be able to see and study his weird works thoroughly. Unfortunately, he has been caught by royal guard soldiers of Basm and is now in his prison. Basm ordered him to solve a problem if he wants to stay alive. King Basm wants to change the structure of roads of his newly captured territory, KuPellaKes in such a way that each city has an even number of neighboring cities. Now, he wants to know the minimum number of roads that should be destroyed in order to satisfy this condition. Note that each city must have at least one neighbor city after the road destruction process. Also, It should be noted that in the given territory at most two cites of KuPellaKes have an odd number of neighboring cities and there is at most one road between two cities. Also, there is no road from a city to itself.

 

The Input

Input consists of several test-cases. Each test-case starts with a line containing three numbers m indicating the number of cities and roads in KuPellaKes respectively. Next m lines, each containing two numbers  indicating that there is a road between the th and the th city. Note that all the roads are bidirectional. Input will be terminated with a line containing three zeros.

 

The Output

For each test-case, your program should output the minimum number of roads that should be destroyed. In the case that this task is impossible the phrase “Poor Koorosh” should be printed.

 

Sample Input

4 5

1 2

2 3

3 4

4 1

1 3

0 0

 

Sample Output

1


Amirkabir University of Technology - Local Contest - Round #2


容易看出原图中要么没有奇点,要么有2个。减少一条边,会使总度数减2,而最终的图,所有点的度数都必须是偶数,这个2度只能减在原图中的2个奇点,其他的点被减的度数都是2,这么看来,就是找一条路从一个奇点到另一个奇点。而要边数最少,所以是求最短路。注意,题目要求剩下的点的度数不能为0。

#include<cstdio>
#include<map>
#include<queue>
#include<cstring>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int maxn = 1000 + 5;
const int INF = 1000000000;
typedef long long LL;
typedef pair<int, int> P;

vector<int> G[maxn];
int degree[maxn];
int S, T;
int vis[maxn];

int bfs(){
    queue<P> q;
    while(!q.empty()) q.pop();
    q.push(P(S, 0));
    memset(vis, 0, sizeof(vis));
    vis[S] = 1;
    while(!q.empty()){
        P p = q.front();
        q.pop();
        int pos = p.first;
        int step = p.second;
        if(G[pos].size()<=2) continue;
        if(pos == T) return step;
        for(int i = 0;i < G[pos].size();i++){
            int to = G[pos][i];
            if(!vis[to]){
                vis[to] = 1;
                q.push(P(to, step+1));
            }
        }
    }
    return -1;
}

int main(){
    int n ,m;
    while(scanf("%d%d", &n, &m)){
        if(n == 0 && m == 0) break;
        for(int i = 1;i <= n;i++){
            G[i].clear();
        }
        memset(degree, 0, sizeof degree);
        while(m--){
            int u, v;
            scanf("%d%d", &u, &v);
            G[u].push_back(v);
            G[v].push_back(u);
            degree[u]++;
            degree[v]++;
        }
        S = T = -1;
        int ans = INF;
        for(int i = 1;i <= n;i++){
            if(degree[i]==0){
                ans = -1;
            }
        }
        for(int i = 1;i <= n;i++){
            if(degree[i]%2==1){
                S = i;
                break;
            }
        }
        for(int i = n;i >= 1;i--){
            if(degree[i]%2==1){
                T = i;
                break;
            }
        }
        if(S == T){
            ans = min(ans, 0);
        }
        else
            ans = min(ans, bfs());
        if(ans == -1)
            printf("Poor Koorosh\n");
        else
            printf("%d\n", ans);
    }
    return 0;
}


【无人机】基于改进粒子群算法的无人机路径规划研究[和遗传算法、粒子群算法进行比较](Matlab代码实现)内容概要:本文围绕基于改进粒子群算法的无人机路径规划展开研究,重点探讨了在复杂环境中利用改进粒子群算法(PSO)实现无人机三维路径规划的方法,并将其与遗传算法(GA)、标准粒子群算法等传统优化算法进行对比分析。研究内容涵盖路径规划的多目标优化、避障策略、航路点约束以及算法收敛性和寻优能力的评估,所有实验均通过Matlab代码实现,提供了完整的仿真验证流程。文章还提到了多种智能优化算法在无人机路径规划中的应用比较,突出了改进PSO在收敛速度和全局寻优方面的优势。; 适合人群:具备一定Matlab编程基础和优化算法知识的研究生、科研人员及从事无人机路径规划、智能优化算法研究的相关技术人员。; 使用场景及目标:①用于无人机在复杂地形或动态环境下的三维路径规划仿真研究;②比较不同智能优化算法(如PSO、GA、蚁群算法、RRT等)在路径规划中的性能差异;③为多目标优化问题提供算法选型和改进思路。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注算法的参数设置、适应度函数设计及路径约束处理方式,同时可参考文中提到的多种算法对比思路,拓展到其他智能优化算法的研究与改进中。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值