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忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...
随机推荐
- Vue.js - Day3
定义Vue组件 什么是组件: 组件的出现,就是为了拆分Vue实例的代码量的,能够让我们以不同的组件,来划分不同的功能模块,将来我们需要什么样的功能,就可以去调用对应的组件即可: 组件化和模块化的不同: ...
- Python人工智能之初识接口
本节需要的两个工具: 1.FFmpeg: 链接:https://pan.baidu.com/s/1jonSAa_TG2XuaJEy3iTmHg 密码:w6hk 2.baidu-aip: pip ins ...
- CSS Grid 布局学习笔记
CSS Grid 布局学习笔记 好久没有写博客了, MDN 上关于 Grid 布局的知识比较零散, 正好根据我这几个月的实践对 CSS Grid 布局做一个总结, 以备查阅. 1. 基础用法 Grid ...
- [原创]在Windows Server 2019上配置NAS
序言 此教程安装的都是最新版本的.由于是当NAS让它非常稳定的运行,所以能不安装的软件尽量不要安装. 一.准备工作 [更新系统] 没啥,就他喵想用个最新的. 右键点击开始键->设置->更新 ...
- 将caj转换成pdf
1.工具准备 电脑一台 CAJViewer 7.2 foxit pdf reader [主是要拥有一个pdf的虚拟打印机,你也可以安装其他的可以取的pdf虚拟打印机的软件.] 2.步骤 (1)用CAJ ...
- org.springframework.beans.factory.BeanNotOfRequiredTypeException
写一个代码:关于Spring Bean的装配.基于annotation实现的范例代码. 出现了错误: 十一月 14, 2018 4:51:01 下午 org.springframework.conte ...
- Tomcat配置文件server.xml分析
本文力求,分析清楚 tomcat 的 server.xml 文件,逐步完善更新 常用来,配置tomcat启动,端口号:配置编码等. apache-tomcat-9.0.10/conf/server.x ...
- 关于java中的hashcode和equals方法原理
关于java中的hashcode和equals方法原理 1.介绍 java编程思想和很多资料都会对自定义javabean要求必须重写hashcode和equals方法,但并没有清晰给出为何重写此两个方 ...
- GL格式一览表
- PHP编译安装时常见错误及解决办法,大全
1. configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution ...