POJ2139 解题报告
2017-07-21 11:20
323 查看
Six Degrees of Cowvin Bacon
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
Sample Output
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 .]
Source
USACO 2003 March Orange
这是一个简单的求 任意两点之间最短路 的问题
使用Floyd算法可以很快地解决
不过这一题由于一开始没有理解题意所以wa了
这一题的大意是,求解出一头离其他的牛距离之和最小的牛,然后算出这个距离之和的平均值再乘上100,得出来的就是答案
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 5769 | Accepted: 2714 |
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 .]
Source
USACO 2003 March Orange
这是一个简单的求 任意两点之间最短路 的问题
使用Floyd算法可以很快地解决
不过这一题由于一开始没有理解题意所以wa了
这一题的大意是,求解出一头离其他的牛距离之和最小的牛,然后算出这个距离之和的平均值再乘上100,得出来的就是答案
#include<iostream> #include<algorithm> using namespace std; const int INF=1000; const int maxn=300+30; const int maxm=10000+100; int dp[maxn][maxn]; int cows[maxn]; int ncow; int N,M; void set_cows(); void floyd(); void solve(); void show(); int main() { while(cin>>N>>M) { fill(dp[0],dp[0]+maxn*maxn,INF); for(int i=0;i<M;i++) { cin>>ncow; for(int i=0;i<ncow;i++) cin>>cows[i]; set_cows(); } floyd(); //show(); solve(); } return 0; } void set_cows() { for(int i=0;i<ncow;i++) for(int j=0;j<ncow;j++) if(i!=j) dp[cows[i]][cows[j]]=dp[cows[j]][cows[i]]=1; else dp[cows[i]][cows[j]]=dp[cows[j]][cows[i]]=0; } void floyd() { for(int k=1;k<=N;k++) for(int i=1;i<=N;i++) for(int j=1;j<=N;j++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]); } void solve() { int sum,min_sum=INF; for(int i=1;i<=N;i++) { sum=0; for(int j=1;j<=N;j++) sum+=dp[i][j]; min_sum=min(sum,min_sum); } cout<<min_sum*100/(N-1)<<endl; } void show() { for(int i=1;i<=N;i++) { for(int j=1;j<=N;j++) if(dp[i][j]<INF) cout<<dp[i][j]<<" "; else cout<<"inf "; cout<<endl; } }
相关文章推荐
- POJ-3325-ICPC Score Totalizer Software-解题报告
- poj - 1185 炮兵阵地 状压DP 解题报告
- POJ 2524 Ubiquitous Religions 解题报告(并查集)
- poj 2689解题报告(区间筛素数,经典)
- poj 2136 Vertical Histogram 解题报告
- poj解题报告——3253
- POJ 1001 解题报告 高精度大整数乘法模版
- POJ 1018 解题报告
- POJ 1157解题报告
- poj 1107解题报告
- POJ-3087 Shuffle'm Up 解题报告
- Polya 定理 (附POJ 1286 Necklace of Beads 解题报告)
- PKU POJ 3630解题报告(trie树)
- POJ 3528 Ultimate Weapon三维凸包(解题报告)
- POJ 1222-EXTENDED LIGHTS OUT解题报告
- 【解题报告】 POJ 1113 Wall -- 求凸包周长
- poj 1905Expanding Rods(二分法)(解题报告)
- POJ 3159 Candies 解题报告(差分约束 Dijkstra+优先队列 SPFA+栈)
- POJ_1014 Dividing解题报告
- POJ 3630 Phone List(解题报告)