10099 The Tourist Guide

题意:给出n的城市m条通道,然后每条通道最大的承载人数给出来了,然后给出起点和终点以及要搭载的人数,问最少要走多少次才能把全部游客送到目的地

因为导游每次都要跟团,所以每条交通道路搭载的最大人数要减1= =

克鲁斯卡尔算法,就会排序的时候按照运输人数的从大到小排序,然后当起点和终点在一个联通分支时即可

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10000;
int n,m;
int p[maxn];
struct node
{
    int u,v,num;
};
bool cmp(node a,node b)
{
    return a.num>b.num;
}
void init()
{
    for(int i=1;i<=n;i++)
    p[i]=i;
}
int find(int x)
{
    return p[x]==x ? x :find(p[x]);
}
node a[maxn];
int main()
{
    int t=0;
    while(scanf("%d %d",&n,&m)!=EOF)
    {
        if(!n&&!m)
        break;
        init();
        for(int i=0;i<m;i++)
        {
            scanf("%d %d %d",&a[i].u,&a[i].v,&a[i].num);
        }
        sort(a,a+m,cmp);
        int s,e,sum;
        scanf("%d %d %d",&s,&e,&sum);
        int k=0;
        for(int i=0;i<m;i++)
        {
            int fx=find(a[i].u);
            int fy=find(a[i].v);
            if(fx!=fy)
            p[fx]=fy;
            if(find(s)==find(e))
            {
                k=i;
                break;
            }
        }
        int num=a[k].num;
        num--;
        int ans;
        if(sum%num==0)
        ans=sum/num;
        else
        ans=sum/num+1;
        printf("Scenario #%d\n",++t);
        printf("Minimum Number of Trips = %d\n\n",ans);
    }
    return 0;
}
时间: 2024-08-05 02:36:21

10099 The Tourist Guide的相关文章

[uva] 10099 - The Tourist Guide

10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1040 Mr.G.自己也算一个人……… 反映到代码里是127行 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3

uva 10099 The Tourist Guide nyoj 1019 亲戚来了【单个路线最大流【最短路算法】】

题目:uva 10099 The Tourist Guide nyoj 1019 亲戚来了 题意:给出一个无向图,每条路有一个容量.从 s 到 t 的一条最大的流量. 分析:这个题目可以用最短路的算法来做,最短路是求从 s 到 t 的最短路,这里是求从 s 到 t 的最小容量.最短路的三种算法都可以. nyoj的使我们比赛的题目,有坑,图有重边,要处理,还有s可能等于t. spfa代码: #include <cstdio> #include <iostream> #include

uva 10099 The Tourist Guide(单源最短路/spfa/dijkstra)

题目: 链接:点击打开链接 题意: 思路: 代码: #include <iostream> #include <cstring> #include <cstdio> using namespace std; int map[101][101]; void floyd(int n) { for(int k=1; k<=n; k++) for(int i=1; i<=n; i++) for(int j=1; j<=n; j++) map[i][j] = m

UVA 10099 The Tourist Guide【floyd】

题目链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1040 题意: n个点,m条路径,每条路径最多通过人数最多为value人,求把v个游客从a点运送到b点,需要几辆车,注意导游自己也算一个人. 思路:floyd找出两点间最大运送量,然后计算需要几躺即可 代码: #include <stdio.h> #include &

UVA10099 - The Tourist Guide(floyd + 最小值的最大化)

UVA10099 - The Tourist Guide(floyd + 最小值的最大化) UVA10099 - The Tourist Guide 题目大意: 给一无向图,图上的点代表城市,边代表路,每条边上的权值代表的是这条路上的巴士的最大乘客数,作为导游,给定起点和终点,和负责的游客,问需要的最少的趟数可以将这个游客送到终点. 解题思路: 路径上最小值的最大化.减少趟数,那么就的要求这条路上的可负载乘客量尽量要大,注意每一趟导游都要跟上.floyd最短路过程中,记录下路径上的最大值. G[

UVa10099_The Tourist Guide(最短路/floyd)(小白书图论专题)

解题报告 题意: 有一个旅游团现在去出游玩,现在有n个城市,m条路.由于每一条路上面规定了最多能够通过的人数,现在想问这个旅游团人数已知的情况下最少需要运送几趟 思路: 求出发点到终点所有路当中最小值最大的那一条路. 求发可能有多种,最短路的松弛方式改掉是一种,最小生成树的解法也是一种(ps,prime和dijs就是这样子类似的) #include <iostream> #include <cstdio> #include <cstring> #include <

floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253

The Tourist Guide Mr. G. works as a tourist guide. His current assignment is to take some tourists from one city to another. Some two-way roads connect the cities. For each pair of neighboring cities there is a bus service that runs only between thos

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

计划,,留

下面给出的题目共计560道,去掉重复的也有近500题,作为ACMer Training Step1,用1年到1年半年时间完成.打牢基础,厚积薄发. 一.UVaOJ http://uva.onlinejudge.org 西班牙Valladolid大学的程序在线评测系统,是历史最悠久.最著名的OJ. 一.<算法竞赛入门经典> 刘汝佳 (UVaOJ 351道题) 以下部分内容摘自:http://sdkdacm.5d6d.com/thread-6-1-1.html "AOAPC I"