【图论floyd】 poj 2139 Six Degrees of Cowvin Bacon
来源:互联网 发布:javaweb高级编程 源码 编辑:程序博客网 时间:2024/06/17 22:43
/*奶牛演电影,演同一部电影的奶牛距离为一,求一个到所有奶牛距离和最小的 奶牛,结果为ans*100/(n-1) n为奶牛数,m为电影数 每行第一个数为参演这部电影的奶牛数*/#include<cstdio>#include<algorithm>#include<iostream>using namespace std;const int inf=1<<29;int f[400][400];int a[400];int n,m,t;void floyd(){ for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) if(f[i][j]>f[i][k]+f[k][j]) f[i][j]=f[i][k]+f[k][j];}int main(){ while(cin>>n>>m) { for(int i=1;i<=n;i++) {for(int j=1;j<=n;j++) { f[i][j]=inf; } f[i][i]=0; } /* while(m--) { cin>>t; for(int i=0; i<t; ++i) { scanf("%d", &a[i]); for(int j=0; j<i; ++j)//j一定得小于i!!! f[a[i]][a[j]] = f[a[j]][a[i]] = 1; } } */ for(int i=1;i<=m;i++) { cin>>t; for(int j=1;j<=t;j++) { cin>>a[j]; for(int k=1;k<j;k++) f[a[j]][a[k]]=f[a[k]][a[j]]=1; } } /*for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { cout<<" "<<f[i][j]; } cout<<endl; }*/ floyd(); int ans=inf; for(int i=1;i<=n;i++) { int ret =0; for(int j=1;j<=n;j++) { ret+=f[i][j]; } ans=ans>ret?ret:ans; } cout<<ans*100/(n-1)<<endl; }}
0 0
- 【图论floyd】 poj 2139 Six Degrees of Cowvin Bacon
- poj 2139 Six Degrees of Cowvin Bacon (Floyd 算法)
- POJ 2139 - Six Degrees of Cowvin Bacon(floyd)
- poj 2139 Six Degrees of Cowvin Bacon , floyd
- poj 2139 Six Degrees of Cowvin Bacon floyd算法
- POJ 2139-Six Degrees of Cowvin Bacon(最短路Floyd)
- Six Degrees of Cowvin Bacon (poj 2139 最短路Floyd)
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
- Poj 2139 Six Degrees of Cowvin Bacon【floyd】
- POJ 2139 Six Degrees of Cowvin Bacon【floyd】
- POJ 2139 Six Degrees of Cowvin Bacon Floyd最短路
- POJ 2139 Six Degrees of Cowvin Bacon
- poj 2139--Six Degrees of Cowvin Bacon
- POJ-2139-Six Degrees of Cowvin Bacon
- POJ 2139 Six Degrees of Cowvin Bacon
- Six Degrees of Cowvin Bacon.(POJ-2139)
- POJ 2139 Six Degrees of Cowvin Bacon
- POJ 2139 Six Degrees of Cowvin Bacon
- 如何解决outlook只能收到163邮箱部分邮件
- 360测试面试一面
- 【C#】浅谈DataSet与DataTable
- 全局变量和局部变量
- Android 网页源码查看器(URLConnection以及handler助手)
- 【图论floyd】 poj 2139 Six Degrees of Cowvin Bacon
- 大数据闲谈及前景展望
- C语言字符串相关知识点
- Struts2获取Servlet API的两种方式
- 初识awk
- 107. Binary Tree Level Order Traversal II
- OpenStack-Ironic裸金属简介
- 计算工作日的问题——SQL编程
- 自考总结—2017年4月