POJ:2139-Six Degrees of Cowvin Bacon
传送门:http://poj.org/problem?id=2139
Six Degrees of Cowvin Bacon
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 6709 Accepted: 3122
Description
The cows have been making movies lately, so they are ready to play a variant of the famous game “Six Degrees of Kevin Bacon”.
The game works like this: each cow is considered to be zero degrees of separation (degrees) away from herself. If two distinct cows have been in a movie together, each is considered to be one ‘degree’ away from the other. If a two cows have never worked together but have both worked with a third cow, they are considered to be two ‘degrees’ away from each other (counted as: one degree to the cow they’ve worked with and one more to the other cow). This scales to the general case.
The N (2 <= N <= 300) cows are interested in figuring out which cow has the smallest average degree of separation from all the other cows. excluding herself of course. The cows have made M (1 <= M <= 10000) movies and it is guaranteed that some relationship path exists between every pair of cows.
Input
Line 1: Two space-separated integers: N and M
Lines 2..M+1: Each input line contains a set of two or more space-separated integers that describes the cows appearing in a single movie. The first integer is the number of cows participating in the described movie, (e.g., Mi); the subsequent Mi integers tell which cows were.
Output
- Line 1: A single integer that is 100 times the shortest mean degree of separation of any of the cows.
Sample Input
4 2
3 1 2 3
2 3 4
Sample Output
100
Hint
[Cow 3 has worked with all the other cows and thus has degrees of separation: 1, 1, and 1 – a mean of 1.00 .]
中文题意:
数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算。
在这里定义人与人的距离:
1.自己与自己的距离为0
2.如果A和B属于同一个小团体,那么他们之间的距离为1
3.如果A与B属于一个小团体,B与C属于一个小团体,且A与C不同属于任何一个小团体,那么A与C的距离为2(A联系C,经过B、C两个人)
4.以此类推
班里有N个人 (2 <= N <= 300),共有M对小团体关系(1 <= M <= 10000)。现在,给你所有班级中小团体的信息,问你班里人缘最好的人到其他人的平均距离。(你需要输出平均距离的100倍)
Input
第一行输入两个证书N,M 接下来的M+1行。
每行开头一个整数K表示本小团体大小,然后接下来K个整数表示小团体内学生编号。
Output
输出一行:最小的平均距离*100(程序中请不要使用Float和Double计算,可能会判Wa)
Sample Input
4 2
3 1 2 3
2 3 4
Sample Output
100
解题心得:
- 其实就是一个建图的问题,直接将同一个团体里面的人都添加一条边,距离是100,不建立其他的边,枚举每个点跑最短路就行了。
#include <stdio.h>
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int maxn = 310;
int maps[maxn][maxn],Time[maxn],Min = 0x7f7f7f7f;
bool vis[maxn];
int n,m;
void init() {
int num[10010];
memset(maps,0,sizeof(maps));
for(int z=0;z<m;z++) {
int cnt;
scanf("%d",&cnt);
for(int i=0;i<cnt;i++) {
scanf("%d",&num[i]);
}
for(int i=0;i<cnt;i++)
for(int j=0;j<i;j++) {
maps[num[i]][num[j]] = maps[num[j]][num[i]] = 100;
}
}
}
void spfa(int s) {
memset(Time,0x7f,sizeof(Time));
queue <int> qu;
qu.push(s);
Time[s] = 0;
while(!qu.empty()) {
int now = qu.front(); qu.pop();
vis[now] = false;
for(int i=1;i<=n;i++) {
if(maps[now][i]) {
if(Time[i] > Time[now] + maps[now][i]) {
Time[i] = Time[now] + maps[now][i];
if(!vis[i]) {
qu.push(i);
vis[i] = true;
}
}
}
}
}
}
void get_sum_path() {
int sum = 0;
for(int i=1;i<=n;i++) {
sum += Time[i];
}
if(sum < Min)
Min = sum;
}
int main() {
scanf("%d%d",&n,&m);
init();
for(int i=1;i<=n;i++) {
spfa(i);
get_sum_path();
}
printf("%d",Min/(n-1));
return 0;
}
POJ:2139-Six Degrees of Cowvin Bacon的更多相关文章
- 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 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 131072/65536K (Ja ...
- <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 ...
- warshall-floyd算法:POJ No 2139 Six Degress of Cowvin Bacon(任意两点最短路径))
题目: http://poj.org/problem?id=2139 题解:N只牛,在一组的两只牛,分别两只之间为 “1度”,自己到自己为0度,M组牛.求,N只牛之中,两只牛之间 平均最短度数*100 ...
- 任意两点间最短距离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)
题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...
- POJ 2139 Six Degrees of Cowvin Bacon (弗洛伊德最短路)
题意:奶牛拍电影,如果2个奶牛在同一场电影里演出,她们的合作度是1,如果ab合作,bc合作,ac的合作度为2,问哪一头牛到其他牛的合作度平均值最小再乘100 思路:floyd模板题 #include& ...
- POJ 2139 Six Degrees of Cowvin Bacon
水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...
- 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)
Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
随机推荐
- Android Studio 小技巧(1):如何导入AAR文件
1. 导入AAR.JAR文件 File- > New -> New Module 这样子AAR文件就导入了,然后在app中的build.gradle中做如下添加 dependencies ...
- VS 打开时默认使用管理员权限
1. 打开VS的安装目录,找到devenv.exe,右键,选择“兼容性疑难解答”. 2. 选择“疑难解答程序” 3. 选择“该程序需要附加权限” 4. 确认用户帐户控制后,点击测试程序,不然这个对话框 ...
- Python ssh连接Linux服务器报Incompatible ssh peer (no acceptable kex algorithm) 解决方法
python通过ssh连接linux服务器,部分服务器出现如下异常 03:50:48.725 FAIL ftp operation failed, Incompatible ssh peer (no ...
- 在VirtualBox ubuntu/linux虚拟机中挂载mount共享文件夹
referemce: https://www.smarthomebeginner.com/mount-virtualbox-shared-folder-on-ubuntu-linux/ 1) Virt ...
- AttributeError: module 'requests' has no attribute 'get' 遇到了这个错误,是因为我把python关键字做了包名。。。
初学者总会犯各种低级错误,这是其一,特此记录.
- IOS item属性总结
一.UINavigationItem1> 获得方式self.navigationItem // self是指控制器 2> 作用可以用来设置当前控制器顶部导航栏的内容// 设置导航栏中间的内 ...
- css3弹性盒子
CSS3 弹性盒子(Flex Box) 弹性盒子是 CSS3 的一种新的布局模式. CSS3 弹性盒( Flexible Box 或 flexbox),是一种当页面需要适应不同的屏幕大小以及设备类型时 ...
- MD5的32位加密方法
/// <summary> /// MD532位加密方式 /// </summary> /// <param name="str">用户原始密码 ...
- 【UOJ139】【UER #4】被删除的黑白树(贪心)
点此看题面 大致题意: 请你给一棵树黑白染色,使每一个叶结点到根节点的路径上黑节点个数相同. 贪心 显然,按照贪心的思想,我们要让叶结点到根节点的路径上黑节点的个数尽量大. 我们可以用\(Min_i\ ...
- vuejs样式绑定
第一种:class的对象绑定,class引用的是一个对象,这个对象的属性显示不显示由变量决定 <style> .activated{ color:red; } </style> ...