POJ1125 Stockbroker Grapevine
来源:互联网 发布:淘宝全球购手机 编辑:程序博客网 时间:2024/05/16 17:41
题目:http://acm.pku.edu.cn/JudgeOnline/problem?id=1125
思路:佛洛依德算法,求出每对点的最短距离。最后枚举每行(即每个人),找每个人最大的,所有人中最小的。
- import java.io.BufferedInputStream;
- import java.io.IOException;
- import java.util.Scanner;
- public class Main {
- final static int MAXVALUE = 10000000;
- public static void main(String[] args) throws NumberFormatException,
- IOException {
- Scanner read = new Scanner(new BufferedInputStream(System.in));
- int t, num;
- int[][] p;
- int min, max, start;
- while ((t = read.nextInt()) != 0) {
- p = new int[t][t];
- for (int i = 0; i < t; i++) {
- for (int j = 0; j < t; j++) {
- p[i][j] = MAXVALUE;
- }
- }
- for (int i = 0; i < t; i++) {
- p[i][i] = 0;
- }
- for (int i = 0; i < t; i++) {
- num = read.nextInt();
- for (int j = 0; j < num; j++) {
- p[i][read.nextInt() - 1] = read.nextInt();
- }
- }
- for (int k = 0; k < t; k++) {
- for (int i = 0; i < t; i++) {
- for (int j = 0; j < t; j++) {
- if (p[i][j] > p[i][k] + p[k][j]) {
- p[i][j] = p[i][k] + p[k][j];
- }
- }
- }
- }
- min = Integer.MAX_VALUE;
- start = -1;
- loop: for (int i = 0; i < t; i++) {
- max = Integer.MIN_VALUE;
- for (int j = 0; j < t; j++) {
- if (p[i][j] == MAXVALUE) {
- continue loop;
- } else {
- max = Math.max(max, p[i][j]);
- }
- }
- if (max < min) {
- min = max;
- start = i;
- }
- }
- if (start != -1) {
- System.out.println((start + 1) + " " + min);
- } else {
- System.out.println("disjoint");
- }
- }
- }
- }
- POJ1125 Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- poj1125 Stockbroker Grapevine
- poj1125 - Stockbroker Grapevine
- POJ1125--Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- poj1125 Stockbroker Grapevine
- poj1125--Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine 【Floyd】
- POJ1125 Stockbroker Grapevine
- POJ1125 - Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine【Floyd】
- POJ1125 Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- POJ1125 Stockbroker Grapevine
- poj1125 Stockbroker Grapevine
- [POJ1125]-Stockbroker Grapevine
- POJ1125-Stockbroker Grapevine
- 利用ALVTree显示BOM结构
- CommonDialog1
- msoFiledialogSaveAs 类型文件框如何使用?
- 中国古代如何严惩食品造假者
- Oracle数据库临时表管理心得
- POJ1125 Stockbroker Grapevine
- PHP - PDT - HTML Syntax Validator (for PHP Files)
- 哈佛图书馆墙上的训言
- 翻转句子中单词的顺序
- 职位分析:Firmware Engineer
- 黑客是怎样炼成的
- coredll.dll
- SSH整合(1)-最小整合框架
- Dotnet B/S 架构学习笔记_02(2008-10-06)