poj2139 Six Degrees of Cowvin Bacon
思路:
floyd
实现:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std; int a[][], n, m, k;
const int INF = 0x3f3f3f3f;
int main()
{
memset(a, 0x3f, sizeof(a));
cin >> n >> m;
for (int i = ; i < m; i++)
{
vector<int> l;
int tmp;
cin >> k;
for (int j = ; j < k; j++)
{
cin >> tmp;
l.push_back(tmp);
}
for (int p = ; p < k; p++)
{
for (int q = ; q < k; q++)
{
a[l[p]][l[q]] = p == q ? : ;
}
}
}
for (int k = ; k <= n; k++)
{
for (int i = ; i <= n; i++)
{
for (int j = ; j <= n; j++)
{
if (a[i][k] + a[k][j] < a[i][j])
{
a[i][j] = a[i][k] + a[k][j];
}
}
}
}
double __ = INF;
for (int j = ; j <= n; j++)
{
int sum = ;
for (int k = ; k <= n; k++)
{
sum += a[j][k];
}
double ans = sum * 1.0 / (n - );
__ = min(ans, __);
}
cout << (int)(__ * ) << endl;
return ;
}
poj2139 Six Degrees of Cowvin Bacon的更多相关文章
- POJ2139 Six Degrees of Cowvin Bacon [Floyd]
水题,随手敲过 一看就是最短路问题,a,b演同一场电影则他们的距离为1 默认全部两两原始距离无穷,到自身为0 输入全部数据处理后floyd 然后照它说的求平均分离度 再找最小的,×100取整输出 #i ...
- 【Floyd】POJ2139 -Six Degrees of Cowvin Bacon
普通的Floyd了分分秒可以水过,结果在submit前删调试段落的时候把程序本体给删了吃了两个WA…… #include<iostream> #include<cstring> ...
- 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 (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
- POJ 2139 Six Degrees of Cowvin Bacon (floyd)
Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- POJ:2139-Six Degrees of Cowvin Bacon
传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...
- <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 ...
- POJ2139--Six Degrees of Cowvin Bacon(最简单Floyd)
The cows have been making movies lately, so they are ready to play a variant of the famous game &quo ...
- POJ-2139 Six Degrees of Cowvin Bacon---Floyd
题目链接: https://vjudge.net/problem/POJ-2139 题目大意: 给定一些牛的关系,他们之间的距离为1. 然后求当前这只牛到每只牛的最短路的和,除以 n - 1只牛的最大 ...
随机推荐
- YTU 2832: 使用指针访问数组元素--程序填空
2832: 使用指针访问数组元素--程序填空 时间限制: 1 Sec 内存限制: 128 MB 提交: 328 解决: 160 题目描述 输入10个整数值到数组中,使用指针来完成对这10个数组元素 ...
- JavaScript Map对象的实现
1. [代码]js代码 /* * MAP对象,实现MAP功能 * * 接口: * size() 获取MAP元素个数 * isEmpty() 判断MAP是否为空 * clear() ...
- JS截取与分割字符串常用技巧总结
本文实例讲述了JS截取与分割字符串的常用方法.分享给大家供大家参考,具体如下: JS截取字符串可使用 substring()或者slice() 函数:substring() 定义:substring( ...
- [Selenium] The commonly used operation of element
btnLogin.click(); //Click element SeleniumUtil.jsClick(driver, saveButtonEl); //If click() ...
- iOS 堆和栈的区别和联系
堆和栈的区别主要有以下五点: 1.管理方式:对于栈来讲,是由编译器自动管理,无需我们手工控制:对于堆来讲,释放工作由程序员控制,容易产生memory leak(内存泄露). 2.申请大小: 栈是向低地 ...
- macbook pro 一些操作经验记录
[一]启用root用户 (1)打开终端 (2)输入命令:sudo passwd root (3)给root设置密码 (4)然后再终端输入命令:su root 进行登陆 [二]解压eclipse压缩包, ...
- hdoj3183【思维】
思路: 处理方案非常霸气啊,无奈想不到. 说是n位去m个,那么默认就是取了n-m个数字,ok,然后m #include <iostream> #include <stdio.h> ...
- python __builtins__ set类 (60)
60.'set', 转换为集合类型 class set(object) | set() -> new empty set object | set(iterable) -> new se ...
- bzoj 4145: [AMPPZ2014]The Prices【状压dp】
设f[s][i]为已经买了集合s,当前在商店i,转移的话就是枚举新买的物品,两种情况,一种是在原商店买,不用付路费,另一种是从其他商店过来,这种再枚举从那个商店过来是不行的,记一个mn[s]为已经买了 ...
- 跟我一起玩Win32开发(20):浏览文件夹
最近忙于一些相当无聊的事情,还没忙完,不过,博客还是要写的,不然我头顶上会多了几块砖头. 在上一篇博文中,我们浏览了文件,今天我们也浏览一下目录,如何? 浏览目录我们同样有两个规矩,用托管类库的我就不 ...