POJ-2139 Six Degrees of Cowvin Bacon---Floyd
题目链接:
https://vjudge.net/problem/POJ-2139
题目大意:
给定一些牛的关系,他们之间的距离为1。
然后求当前这只牛到每只牛的最短路的和,除以 n - 1只牛的最大值。(这里直接取整就行啦)
思路:
floyd来求最短路。
然后枚举求max就行了。
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<map>
#include<cmath>
using namespace std;
typedef pair<int, int> Pair;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int T, n, m;
const int maxn = 2e4 + ;
int Map[][];
int x[];
ll sum[];
void floyd()
{
for(int k = ; k <= n; k++)
{
for(int i = ; i <= n; i++)
{
for(int j = ; j <= n; j++)
{
Map[i][j] = min(Map[i][j], Map[i][k] + Map[k][j]);
}
}
}
ll sum, minn = INF;
for(int i = ; i <= n; i++)
{
sum = ;
for(int j = ; j <= n; j++)
sum += (ll)Map[i][j];
minn = min(minn, sum);
}
int ans = minn * / (n - );
cout<<ans<<endl;
}
int main()
{
cin >> n >> m;
memset(Map, INF, sizeof(Map));
for(int i = ; i <= n; i++)Map[i][i] = ;
while(m--)
{
int t;
cin >> t;
for(int i = ; i < t; i++)cin >> x[i];
for(int i = ; i < t; i++)
for(int j = i + ; j < t; j++)
Map[x[i]][x[j]] = Map[x[j]][x[i]] = ; }
floyd();
}
POJ-2139 Six Degrees of Cowvin Bacon---Floyd的更多相关文章
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...
- <poj - 2139> Six Degrees of Cowvin Bacon 最短路径问题 the cow have been making movies
本题链接:http://poj.org/problem?id=2139 Description: The cows have been making movies lately, so the ...
- POJ 2139 Six Degrees of Cowvin Bacon (Floyd)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- 任意两点间最短距离floyd-warshall ---- POJ 2139 Six Degrees of Cowvin Bacon
floyd-warshall算法 通过dp思想 求任意两点之间最短距离 重复利用数组实现方式dist[i][j] i - j的最短距离 for(int k = 1; k <= N; k++) f ...
- POJ 2139 Six Degrees of Cowvin Bacon
水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- POJ 2139 Six Degrees of Cowvin Bacon (弗洛伊德最短路)
题意:奶牛拍电影,如果2个奶牛在同一场电影里演出,她们的合作度是1,如果ab合作,bc合作,ac的合作度为2,问哪一头牛到其他牛的合作度平均值最小再乘100 思路:floyd模板题 #include& ...
- POJ:2139-Six Degrees of Cowvin Bacon
传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...
- POJ2139 Six Degrees of Cowvin Bacon [Floyd]
水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
随机推荐
- Linux中apache服务
httpd访问控制生成共享文件vim var/www/html/cq/index.html编辑配置文件 vim /etc/httpd/conf/httpd.conf<Directory &quo ...
- Java StringBuffer
String是不变类,用String修改字符串会新建一个String对象,如果频繁的修改,将会产生很多的String对象,开销很大.因此java提供了一个StringBuffer类,这个类在修改字符串 ...
- windows服务开启(收藏url)
windows服务开启(收藏url) http://blog.csdn.net/wanda39kela/article/details/46310093
- 惠普台式机在UEFI BIOS设置通电自动开机 影响电脑自动重启关不了机设置
设置通电自动开机 影响电脑自动重启关不了机设置 惠普台式机在UEFI BIOS中 1. 开机时不断点击F10键进入BIOS,选择Advanced(高级)然后选择Boot Options,点击回车 ...
- my28_mysql内存占用过高降低的方法
对mysql做压力测试,测试完之后,mysql的内存一直不下降 $ free -m total used free shared buff/cache available Mem: Swap: # t ...
- pdf.js使用爬过的坑
最近项目里需要做一个在浏览器直接预览pdf的功能,有些浏览器可以直接预览pdf文件,但是有些不能(不要躲,说的就是你IE)查资料普遍推荐pdf.js,兼容能到ie9,很不错了. 1. 从pdf.js官 ...
- 转载 Some indexes or index [sub]partitions of table VAS.TAB_PUB_CALLLOG have been marked unusable
http://www.xifenfei.com/2011/12/some-indexes-or-index-subpartitions-of-table-vas-tab_pub_calllog-hav ...
- windows下修改了系统变量里java_home所引用的jdk,但是查询jdk的版本并没有发生改变
# 原因:因为%SystemRoot%\system32 在引用这个环境变量时,会默认C:\Windows\System32下的jdk版本 # 解决方法: 把jdk的配置放在path前面就可以了
- C++常用数据结构(对照python)
python: c++17: get set extend/update find index size loop list std::vector v[0]; v.emplace_back(&quo ...
- Trace Logging Level
Trace In functions which support this level, details every parameter and operation to help diagnose ...