解题报告

题意:

有一个旅游团如今去出游玩,如今有n个城市,m条路。因为每一条路上面规定了最多可以通过的人数,如今想问这个旅游团人数已知的情况下最少须要运送几趟

思路:

求出发点到终点全部路其中最小值最大的那一条路。

求发可能有多种。最短路的松弛方式改掉是一种。最小生成树的解法也是一种(ps。prime和dijs就是这样子类似的)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q,mmap[110][110];
void floyd() {
for(int k=0; k<n; k++)
for(int i=0; i<n; i++)
for(int j=0; j<n; j++)
mmap[i][j]=max(mmap[i][j],min(mmap[i][k],mmap[k][j]));
}
int main() {
int i,j,u,v,w,k=1;
while(~scanf("%d%d",&n,&m)) {
if(!n&&!m)break;
for(i=0; i<n; i++) {
for(j=0; j<n; j++)
mmap[i][j]=0;
}
for(i=0; i<m; i++) {
scanf("%d%d%d",&u,&v,&w);
mmap[u-1][v-1]=mmap[v-1][u-1]=w;
}
floyd();
scanf("%d%d%d",&u,&v,&w);
int ans=0,num=mmap[u-1][v-1]-1;
ans=ceil((double)w/num);
printf("Scenario #%d\n",k++);
printf("Minimum Number of Trips = %d\n\n",ans);
}
return 0;
}

The Tourist Guide

Input: standard input

Output: standard output

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, since he has to ride the bus with each group, 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: C1C2 andPC1 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: SD andT 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.

 

Sample Input

7 10

1 2 30

1 3 15

1 4 10

2 4 25

2 5 60

3 4 40

3 6 20

4 7 35

5 7 20

6 7 30

1 7 99

0 0

Sample Output

Scenario #1

Minimum Number of Trips = 5

最新文章

  1. lisp中的cons
  2. 70 sudo-用来以其他身份来执行命令
  3. [SmartFoxServer概述]Zones和Rooms结构
  4. Spring Boot 学习
  5. Async callback to awaitable Task&lt;&gt; z
  6. java_接口的应用
  7. 代码中动态改变布局属性RelativeLayout.LayoutParams.addRule()
  8. java-bootstrap
  9. Feature Extractor[content]
  10. Centos7安装Mysql5.7方法总结 - 实操手册
  11. [c/c++] programming之路(15)、多维数组和二分查找法,小外挂
  12. split根据一个元素分割语句
  13. 收藏pdf 链接
  14. GENIL_BOL_BROWSER 中显示的Object Name 是root object的名字
  15. ajax之发送post请求
  16. JS原生添加删除class的方法
  17. 牛客网NOIP赛前集训营-提高组(第八场)-B-推箱子[最短路优化建图]
  18. Linux下JDK到底应该安装在哪儿?
  19. 初步了解pandas(学习笔记)
  20. Storm:分布式流式计算框架

热门文章

  1. iOS面试_1.浅析内存管理
  2. 【SQL Server】sql server更改了数据表的字段/新增数据表的字段 无法保存
  3. solr6.6 配置自带中文分词
  4. [Javascript] Conditionally spread entries to a JavaScript object
  5. IDEA+MAVEN+testNG(reportNG)
  6. 大话项目管理工具之Jira篇
  7. react 解决 setState 异步问题
  8. 【Python3 爬虫】16_抓取腾讯视频评论内容
  9. poj 3592 Instantaneous Transference 【SCC +缩点 + SPFA】
  10. MongoDB查询经典方式