经纪人(图论,fyold算法)
来源:互联网 发布:java 对比相似度 编辑:程序博客网 时间:2024/04/29 07:38
#include<stdio.h>#include<string.h>#include<iostream>#include<algorithm>using namespace std;int g[100][100];int n;void floyd() //求任意两点的最短路{ int i,j,k; for(k = 0;k < n;k ++) { for(i = 0;i < n;i++) { if(g[i][k] != 0) for(j = 0;j < n;j++) { if(g[k][j] && i != j) { if((g[i][j] == 0) || (g[i][j] > g[i][k] + g[k][j]))//当i和k之间,k和j之间已经连接 g[i][j] = g[i][k] + g[k][j]; } } } }}int main(){ int i,j; int contact,number,time; while(scanf("%d",&n) && n) { memset(g,0,sizeof(g)); for(i = 0;i < n;i++) { scanf("%d",&contact); for(j = 0;j < contact;j++) { scanf("%d %d",&number,&time); g[i][(--number)] = time;//记录时间 } } floyd(); int min = 30000;//初始化为比最大值大一点点,过大会超时 number = -1; for(i = 0;i < n;i++) { time = 0; for(j = 0;j < n;j++) { if(i != j) { if(time < g[i][j]) time = g[i][j]; else if(g[i][j] == 0)//如果有一个点没有覆盖,说明没有形成网,跳出 { time = 30000; break; } } } if(min > time)//更新最小值 { number = i; min = time; } } if(min < 30000) printf("%d %d\n",(++number),min); else printf("disjoint\n"); } return 0;}
Problem H Stockbroker Grapevine
Stockbrokers are known to overreact to rumours. You have been contracted to develop a method of spreading disinformation amongst the stockbrokers to give your employer the tactical edge in the stock market. For maximum effect, you have to spread the rumours in the fastest possible way.
nfortunately for you, stockbrokers only trust information coming from their "Trusted sources" This means you have to take into account the structure of their contacts when starting a rumour. It takes a certain amount of time for a specific stockbroker to pass the rumour on to each of his colleagues. Your task will be to write a program that tells you which stockbroker to choose as your starting point for the rumour, as well as the time it will take for the rumour to spread throughout the stockbroker community. This duration is measured as the time needed for the last person to receive the information.
Input
Your program will input data for different sets of stockbrokers. Each set starts with a line with the number of stockbrokers. Following this is a line for each stockbroker which contains the number of people who they have contact with, who these people are, and the time taken for them to pass the message to each person. The format of each stockbroker line is as follows: The line starts with the number of contacts (n), followed by n pairs of integers, one pair for each contact. Each pair lists first a number referring to the contact (e.g. a '1' means person number one in the set), followed by the time in minutes taken to pass a message to that person. There are no special punctuation symbols or spacing rules.
Each person is numbered 1 through to the number of stockbrokers. The time taken to pass the message on will be between 1 and 10 minutes (inclusive), and the number of contacts will range between 0 and one less than the number of stockbrokers. The number of stockbrokers will range from 1 to 100. The input is terminated by a set of stockbrokers containing 0 (zero) people.
The English words of 0-9 is :zero, one , two , three , four , five , six , seven , eight , nine 。
Output
For each set of data, your program must output a single line containing the person who results in the fastest message transmission, and how long before the last person will receive any given message after you give it to this person, measured in integer minutes.
It is possible that your program will receive a network of connections that excludes some persons, i.e. some people may be unreachable. If your program detects such a broken network, simply output the message "disjoint". Note that the time taken to pass the message from person A to person B is not necessarily the same as the time taken to pass it from B to A, if such transmission is possible at all.
Sample Input
Sample Input
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
0
3 2
- 经纪人(图论,fyold算法)
- 经纪人
- Python爬虫实战(3):安居客房产经纪人信息采集
- [转]技术经纪人
- 社区经理是经纪人
- 与保险经纪人考试面对面
- [转]技术经纪人将成职业新宠
- [转]技术经纪人资格认定暂行办法
- [转]北京市技术经纪人管理暂行办法
- 诺基亚推出手机Java经纪人服务
- 从阳光小宅男 到房产经纪人
- 应遵循获得一个可靠的经纪人
- CIO将成为战略服务经纪人
- 给李娜的经纪人点个赞
- 邓紫棋经纪人狠批林宥嘉不负责任:她是受害者
- 陈奕迅被曝退出歌坛 经纪人:只是修养
- 简书:电子书时代的“出版经纪人”
- 乌兰图雅经纪人雪若13691027567
- 一维数组,二维数组,三维数组名的含义
- IO流解析概述
- android手机通讯录数据库重要表介绍
- MySQL各种存储引擎的对比
- 学习感悟:态度决定一切
- 经纪人(图论,fyold算法)
- HTML事件默认行为与事件传播
- 注释转换
- Java基础回顾 : 线程的实现方式
- Win10系统总是提示"在商店中查找应用"的关闭方法
- Canvas类简介
- hdu 1269 迷宫城堡(tarjan 算法)
- 关于java中一些代码的理解
- Java入门篇