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 those two cities and uses the road that directly connects them. Each bus service has a limit on the maximum number of passengers it can carry. Mr. G. has a map showing the cities and the roads connecting them. He also has the information regarding each bus service. He understands that it may not always be possible for him to take all the tourists to the destination city in a single trip. For example, consider the following road map of 7 cities. The edges connecting the cities represent the roads and the number written on each edge indicates the passenger limit of the bus service that runs on that road.

Now, if he wants to take 99 tourists from city 1 to city 7, he will require at least 5 trips and the route he should take is : 1 - 2 - 4 - 7. But, Mr. G. finds it difficult to find the best route all by himself so that he may be able to take all the tourists to the destination city in minimum number of trips. So, he seeks your help.

Input

The input will contain one or more test cases. The first line of each test case will contain two integers: N (N ≤ 100) and R representing respectively the number of cities and the number of road segments. Then R lines will follow each containing three integers: C1, C2 and P. C1 and C2 are the city numbers and P (P > 1) is the limit on the maximum number of passengers to be carried by the bus service between the two cities. City numbers are positive integers ranging from 1 to N. The (R + 1)-th line will contain three integers: S, D and T representing respectively the starting city, the destination city and the number of tourists to be guided. The input will end with two zeroes for N and R.

Output

For each test case in the input first output the scenario number. Then output the minimum number of trips required for this case on a separate line. Print a blank line after the output of each test case.

 #include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
const int N=;
#define inf 0x3f3f3f3f
int e[N][N];
//int n; //void init(int nn)
//{
// for(int i=1; i<=nn; i++)
// {
// for(int j=1; j<=nn; j++)
// {
// if(i==j)
// e[i][j]=0;
// else
// e[i][j]=inf;
// }
// }
//} int main()
{
int n,m;
int tt=;
while(~scanf("%d %d",&n,&m))
{
// init(n);
if(n==&&m==)
break;
memset(e,,sizeof(e));
int aa,bb,cc;
for(int i=; i<=m; i++)
{
scanf("%d %d %d",&aa,&bb,&cc);
e[aa][bb]=e[bb][aa]=cc-;
// e[aa][bb]=e[bb][aa]=cc;
}
for(int k=; k<=n; k++)
{
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
// if(e[i][j]!=inf&&e[i][k]!=inf&&e[k][j]!=inf)
// e[i][j]=max(e[i][j],e[i][k]+e[k][j]);
e[i][j]=max(e[i][j],min(e[i][k],e[k][j]));
}
}
}
// int tt=1;
// cout<<e[1][7]<<"***"<<endl;
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
int ans=(c-)/e[a][b];
// int ans=c/(e[a][b]-1);
if((c-)%e[a][b]!=)
// if(c%e[a][b]!=0)
ans++;
// ans=ans*2-1;
printf("Scenario #%d\n",tt++);
printf("Minimum Number of Trips = %d\n\n",ans);
}
return ;
}

Frogger

Freddy Frog is sitting on a stone in the middle of a lake. Suddenly he notices Fiona Frog who is sitting on another stone. He plans to visit her, but since the water is dirty and full of tourists' sunscreen, he wants to avoid swimming and instead reach her by jumping. 
Unfortunately Fiona's stone is out of his jump range. Therefore Freddy considers to use other stones as intermediate stops and reach her by a sequence of several small jumps. 
To execute a given sequence of jumps, a frog's jump range obviously must be at least as long as the longest jump occuring in the sequence. 
The frog distance (humans also call it minimax distance) between two stones therefore is defined as the minimum necessary jump range over all possible paths between the two stones.

You are given the coordinates of Freddy's stone, Fiona's stone and all other stones in the lake. Your job is to compute the frog distance between Freddy's and Fiona's stone.

Input

The input will contain one or more test cases. The first line of each test case will contain the number of stones n (2<=n<=200). The next n lines each contain two integers xi,yi (0 <= xi,yi <= 1000) representing the coordinates of stone #i. Stone #1 is Freddy's stone, stone #2 is Fiona's stone, the other n-2 stones are unoccupied. There's a blank line following each test case. Input is terminated by a value of zero (0) for n.

Output

For each test case, print a line saying "Scenario #x" and a line saying "Frog Distance = y" where x is replaced by the test case number (they are numbered from 1) and y is replaced by the appropriate real number, printed to three decimals. Put a blank line after each test case, even after the last one.

Sample Input

2
0 0
3 4 3
17 4
19 4
18 5 0

Sample Output

Scenario #1
Frog Distance = 5.000 Scenario #2
Frog Distance = 1.414
 #include<iostream>
#include<string.h>
#include<cmath>
#include<iomanip>
#define inf 0x3f3f3f3f
using namespace std; //点点之间的距离floyd
//找a-b所有路径中最大步数里面最小的
struct edge
{
// double x;
// double y;
int x;
int y;
} e[]; double a[][];
int n; double d(int x1,int y1,int x2,int y2)
{
return sqrt(((x2-x1)*(x2-x1)*1.0+(y2-y1)*(y2-y1)*1.0)*1.0);
} void init()
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
if(i==j)
a[i][j]=;
else
a[i][j]=inf;
}
}
} int main()
{
std::ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int tt=;
while(cin>>n)
{
if(n==)
break;
memset(e,,sizeof(e));
memset(a,,sizeof(a));
init();
for(int i=; i<=n; i++)//n个顶点
cin>>e[i].x>>e[i].y; // p=1;//p条边 for(int i=; i<=n; i++)
{
for(int j=i+; j<=n; j++)
{
// addedge[p++]=d(e[i].x,e[i].y,e[j].x,e[j].y); double dd=d(e[i].x,e[i].y,e[j].x,e[j].y);
if(a[i][j]>dd||a[j][i]>dd)
{
a[j][i]=a[i][j]=dd;
}
}
}
// sort(addedge+1,addedge+p+1,cmp1);
for(int k=;k<=n;k++)
{
for(int i=;i<=n;i++)
{
for(int j=;j<=n;j++)
{
//if(a[i][j]a[i][k]+a[k][j])
a[i][j]=min(a[i][j],max(a[i][k],a[k][j]));
}
}
}
double dis=a[][];
cout<<"Scenario #"<<tt++<<endl;
cout<<"Frog Distance = ";
cout<<setiosflags(ios::fixed)<<setprecision()<<dis<<endl<<endl;
}
return ;
}

floyd类型题UVa-10099-The Tourist Guide +Frogger POJ - 2253的更多相关文章

  1. [uva] 10099 - The Tourist Guide

    10099 - The Tourist Guide 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemi ...

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

    解题报告 题意: 有一个旅游团如今去出游玩,如今有n个城市,m条路.因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟 思路: 求出发点到终点全部路其中最小值 ...

  3. leetcode 字符串类型题

    1,Vaild Palindrome bool isPalindrome(string& s) { transform(s.begin(), s.end(), s.begin(), tolow ...

  4. UVa 127 - &quot;Accordian&quot; Patience POJ 1214 链表题解

    UVa和POJ都有这道题. 不同的是UVa要求区分单复数,而POJ不要求. 使用STL做会比較简单,这里纯粹使用指针做了,很麻烦的指针操作,一不小心就错. 调试起来还是很费力的 本题理解起来也是挺费力 ...

  5. hdu 2987最大权闭合图模板类型题

    /* 最大权闭合图模板类型的题,考验对知识概念的理解. 题意:如今要辞退一部分员工.辞退每个员工能够的到一部分利益(能够是负的),而且辞退员工,必须辞退他的下属.求最大利益和辞退的最小人数. 最大权闭 ...

  6. 思维题 UVA 10881 Piotr's Ants

    题目传送门 /* 题意:在坐标轴上一群蚂蚁向左或向右爬,问经过ts后,蚂蚁的位置和状态 思维题:本题的关键1:蚂蚁相撞看作是对穿过去,那么只要判断谁是谁就可以了 关键2:蚂蚁的相对位置不变 关键3:o ...

  7. 贪心/思维题 UVA 11292 The Dragon of Loowater

    题目传送门 /* 题意:n个头,m个士兵,问能否砍掉n个头 贪心/思维题:两个数组升序排序,用最弱的士兵砍掉当前的头 */ #include <cstdio> #include <c ...

  8. 纯几何题 --- UVA - 11646 Athletics Track

    这一题题目有点坑,注意这句话: 这代表了其圆心就是矩形的中心! 然后就可以推公式: 可知: x = 200/(a+2atan(b/c)*r); r = sqrt(a*a + b*b); 所以有AC代码 ...

  9. leetcode 链表类型题总结

    链表测试框架示例: // leetcodeList.cpp : 定义控制台应用程序的入口点.vs2013 测试通过 // #include "stdafx.h" #include ...

随机推荐

  1. 10.Struts2值栈

    1.什么是值栈 * 值栈就相当于Struts2框架的数据的中转站,向值栈存入一些数据.从值栈中获取到数据. * ValueStack 是 struts2 提供一个接口,实现类 OgnlValueSta ...

  2. vue之TodoMVC项目实战

    一.初始化项目 1.下载模板 进入github中https://github.com/tastejs/todomvc-app-template,并且在命令行将其clone下来 git clone ht ...

  3. JAVA去除抖音视频的水印源码!!!

    @PostMapping("geturl") public DataResponse decodeDouiyin(@RequestBody DouyinRequest req ) ...

  4. thinlphp配置加载

    在ThinkPHP中,一般来说应用的配置文件是自动加载的,加载的顺序是: 惯例配置->应用配置->模式配置->调试配置->状态配置->模块配置->扩展配置-> ...

  5. Element-UI 的树列表实现单选

    1. Element-UI 的 el-tree 组件当设置了 show-checkbox 属性以后,默认是只能多选的,如果我们想要将其改选为单选,就要进行一些特殊的处理,首先看效果图. 2. 组件代码 ...

  6. js自动下载

    常用方法是利用a标签的属性download下载对应文件.图片等 <a href=".." download="...."></a> 但是 ...

  7. NX二次开发-UFUN获取点在面上的向量方向UF_MODL_ask_face_props【转载】

    1 NX11+VS2013 2 3 4 #include <uf.h> 5 #include <uf_ui.h> 6 #include <uf_modl.h> 7 ...

  8. [JZOJ 5697] 农场

    题目大意:将 n 个数 ai分成若干连续的段,使得每段的和都相等,求最多可以分成多少段. 思路: 考虑ai的和为sum,那么每一段的和就是约数. 对于每一个d,考虑其是否合法. 1e6之内用桶统计不会 ...

  9. Mybatis笔记 - Mybatis框架简介

    MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名为MyBatis,实质上 ...

  10. [02]APUE:POSIX 正则库(#include <regex.h>)

    正则匹配流程: 声明一个 regex_t 类型的变量(结构体) regcomp 函数会将“正则匹配条件”写入此结构体,并编译成特定的二进制格式(加快匹配速度) 声明一个 regmatch_t 类型的变 ...