poj1125

news/2024/10/20 21:12:36/

思路:求出一行的最大值,同时求解出一列中的最下值,并记下下标,采用Floyd算法。

#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxx=1005;
const int inf=0x3f3f3f3f;
int n;
int e[maxx][maxx];
int flag;
void Floy(int n){for(int k=1;k<=n;k++){for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){e[i][j]=min(e[i][j],e[i][k]+e[k][j]);}}}
}
int main(){while(cin>>n){if(n==0)break;flag=1;for(int i=1;i<=n;i++){for(int j=1;j<=n;j++){if(i==j){e[i][j]=0;}else{e[i][j]=inf;}}}for(int i=1;i<=n;i++){int t;cin>>t;for(int j=1;j<=t;j++){int a,time;cin>>a>>time;e[i][a]=time;}}Floy(n);int sum=inf;int maxin;int fast;for(int i=1;i<=n;i++){maxin=0;for(int j=1;j<=n;j++){if(maxin<e[i][j]&&e[i][j]>0){maxin=e[i][j];}}if(maxin<sum){sum=maxin;fast=i;}}if(sum!=inf){cout<<fast<<" "<<sum<<endl;}else{cout<<"disjoint"<<endl;}}return 0;
}

http://www.ppmy.cn/news/373634.html

相关文章

信息学奥赛一本通 1125:矩阵乘法 | OpenJudge NOI 1.8 08

【题目链接】 ybt 1125&#xff1a;矩阵乘法 OpenJudge NOI 1.8 09:矩阵乘法 【题目考点】 1. 二维数组遍历 【题解代码】 解法1&#xff1a; #include<bits/stdc.h> using namespace std; #define N 105 int main() {int m, n, k, a[N][N], b[N][N], r[N][N] {};…

1125: 上三角矩阵的判断

1125: 上三角矩阵的判断 时间限制: 1 Sec 内存限制: 128 MB 提交: 373 解决: 341 [提交] [状态] [讨论版] [命题人:eilene] 题目描述 编写程序&#xff0c;输入一个正整数n&#xff08;1<n<10&#xff09;和n阶方阵a中的元素&#xff0c;如果a是上三角矩阵&#xff…

信息学奥赛一本通(c++):1125:矩阵乘法

信息学奥赛一本通&#xff08;c&#xff09;&#xff1a;1125&#xff1a;矩阵乘法 一、题目 1125&#xff1a;矩阵乘法时间限制: 1000 ms 内存限制: 65536 KB 【题目描述】 计算两个矩阵的乘法。nm阶的矩阵A乘以mk阶的矩阵B得到的矩阵C 是nk阶的&#xff0c;且C[i]…

PAT 1125

第二题很多人都说是赫夫曼树,我就排了个序就过了,之后推敲了一下这个逻辑是可行的,当然赫夫曼树也是正解,有兴趣的同学可以用赫夫曼树做一下 #include<iostream> #include<vector> #include<string> #include<algorithm> using namespace std;int main…

P1125 [NOIP2008 提高组] 笨小猴

P1125 [NOIP2008 提高组] 笨小猴 题目描述 笨小猴的词汇量很小&#xff0c;所以每次做英语选择题的时候都很头疼。但是他找到了一种方法&#xff0c;经试验证明&#xff0c;用这种方法去选择选项的时候选对的几率非常大&#xff01; 这种方法的具体描述如下&#xff1a;假设…

PAT甲级 1125

PAT甲级 1125 题目 Chain the Ropes解析代码 题目 Chain the Ropes Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fold two segments into loops and chain them into one piece, as shown by the figure. The resulti…

P1125

数组/桶的思想&#xff1a;笨小猴 要求 1.计算一个单词中每个字母出现的次数&#xff0c;并找出出现的次数与出现最小的次数 方案 1.利用桶的思想 桶算法模板 用处&#xff1a;记录数组或字符串中每个值出现的次数 场景&#xff1a;字符串&#xff0c;数组&#xff0c;字…

1125 Chain the Ropes

题目 题意&#xff1a;将两段绳子对折连接在一起可获得的最大长度 #include<iostream> #include<algorithm> using namespace std; int main() {int n;cin>>n;int s[n];for(int i0; i<n; i)cin>>s[i];sort(s,sn);int anss[0];for(int i1; i<n;…