poj_1125 Stockbroker Grapevine
来源:互联网 发布:linux开启smb服务 编辑:程序博客网 时间:2024/05/21 05:17
Stockbroker Grapevine
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 20810
Accepted: 11278
题目链接:http://poj.org/problem?id=1125
Description
Stockbrokers are known to overreact to rumours. You havebeen contracted to develop a method of spreading disinformation amongst thestockbrokers to give your employer the tactical edge in the stock market. Formaximum effect, you have to spread the rumours in the fastest possible way.
Unfortunately for you, stockbrokers only trust information coming from their"Trusted sources" This means you have to take into account thestructure of their contacts when starting a rumour. It takes a certain amountof time for a specific stockbroker to pass the rumour on to each of hiscolleagues. Your task will be to write a program that tells you whichstockbroker to choose as your starting point for the rumour, as well as thetime it will take for the rumour to spread throughout the stockbrokercommunity. This duration is measured as the time needed for the last person toreceive the information.
Input
Your program willinput data for different sets of stockbrokers. Each set starts with a line withthe number of stockbrokers. Following this is a line for each stockbroker whichcontains 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 ofeach stockbroker line is as follows: The line starts with the number ofcontacts (n), followed by n pairs of integers, one pair for each contact. Eachpair lists first a number referring to the contact (e.g. a '1' means personnumber one in the set), followed by the time in minutes taken to pass a messageto that person. There are no special punctuation symbols or spacing rules.
Each person is numbered 1 through to the number of stockbrokers. The time takento pass the message on will be between 1 and 10 minutes (inclusive), and thenumber of contacts will range between 0 and one less than the number ofstockbrokers. The number of stockbrokers will range from 1 to 100. The input isterminated by a set of stockbrokers containing 0 (zero) people.
Output
For each set of data, your program must output a singleline containing the person who results in the fastest message transmission, andhow long before the last person will receive any given message after you giveit to this person, measured in integer minutes.
It is possible that your program will receive a network of connections thatexcludes some persons, i.e. some people may be unreachable. If your programdetects 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 notnecessarily the same as the time taken to pass it from B to A, if such transmissionis possible at all.
Sample Input
3
2 2 4 3 5
2 1 2 3 6
2 1 2 2 2
5
3 4 4 2 8 5 3
1 5 8
4 1 6 4 10 2 7 5 2
0
2 2 5 1 5
0
Sample Output
3 2
3 10
Source
Southern African2001
题意:
这个题目到不会难,只是题意挺难理解的,大概讲的是消息在传送,第一行给出消息传送的人数n,接下来n行中的第一个数字表示第i个人可以传递以m个人(a,b)表示传递的编号和时间,问从那个人传送的时间会最快,时间是多少,同一个人传递给多个人时间只算一个最大的。
解题思路:
因为这个题目的数据量比较小,可以用Floyd-Warshall算法来做,这个算法求出每两个点之间的最小距离,在遍历一遍答案就可以出来了
代码:
#include <iostream>#include<cstdio>#include<cstring>#define MAX 103#define VALUE 0xffffffusing namespace std;int g[MAX][MAX];int d[MAX];bool used[MAX];int min(int x,int y){return x<y?x:y;}void Floyd(int n){ int i,j,k; for(k=1;k<=n;k++) for(i=1;i<=n;i++) for(j=1;j<=n;j++) g[i][j]=min(g[i][j],g[i][k]+g[k][j]);//求出任意两点之间的最小值}int main(){ int ts; int i,j; int maxvalue,maxtime,t; while(true) { scanf("%d",&ts); if(ts==0)break; // memset(g,0,sizeof(g)); for(i=1;i<=ts;i++) for(j=1;j<=ts;j++) g[i][j]=VALUE; for(i=1;i<=ts;i++) { int n; scanf("%d",&n); g[i][i]=0; while(n--) { int no,time;//时间和编号 scanf("%d%d",&no,&time); g[i][no]=time;//建图 } } Floyd(ts); maxtime=VALUE; for(i=1;i<=ts;i++) { maxvalue=0; for(j=1;j<=ts;j++) { if(g[i][j]>maxvalue) {//求出最长的边 maxvalue=g[i][j]; } } if(maxvalue<maxtime) { maxtime=maxvalue; t=i; } } if(maxtime==VALUE) { printf("disjoint\n"); } else { printf("%d %d\n",t,maxtime); } } return 0;}
- poj_1125 Stockbroker Grapevine
- POJ_1125 Stockbroker Grapevine
- [POJ_1125]Stockbroker Grapevine
- poj_1125 Stockbroker Grapevine(floyd)
- POJ_1125(folyd算法)Stockbroker Grapevine
- stockbroker grapevine
- Stockbroker Grapevine
- Stockbroker Grapevine
- Stockbroker Grapevine
- Stockbroker Grapevine
- Stockbroker Grapevine
- Stockbroker Grapevine
- zoj1082 Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- JOJ 1002 Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- 1125Stockbroker Grapevine
- pku1125 Stockbroker Grapevine
- 博客搬家
- 浅谈ARM裸板调试
- poj_1041 John's trip
- [已删除]
- 使用NSFileManager枚举目录种的内容(遍历目录)
- poj_1125 Stockbroker Grapevine
- 使用dom4j:读取spring配置文件,实例化bean对象并注入依赖对象
- MFC中动态创建多个按钮并实现其消息响应
- poj_1797 Heavy Transportation
- delphiIDE调试使用小结
- Discuz 。net版下载地址:
- FileZilla Server搭建
- C语言的那些小秘密——字节对齐
- 输入外挂