题意:奶牛拍电影,如果2个奶牛在同一场电影里演出,她们的合作度是1,如果ab合作,bc合作,ac的合作度为2,问哪一头牛到其他牛的合作度平均值最小再乘100

思路:floyd模板题

  1. #include<cstdio>
  2. #include<cmath>
  3. #include<cstring>
  4. #include<iostream>
  5. #include<algorithm>
  6. int f[][],a[];
  7.  
  8. int read(){
  9. char ch=getchar();int f=,t=;
  10. while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
  11. while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
  12. return t*f;
  13. }
  14. int main(){
  15. int n,m;
  16. n=read();m=read();
       memset(f,0x3f3f3f3f,sizeof f);for (int i=;i<=m;i++){
  17. int cnt=read();
  18. for (int j=;j<=cnt;j++)
  19. a[j]=read();
  20. for (int j=;j<=cnt;j++)
  21. for (int k=;k<j;k++)
  22. f[a[j]][a[k]]=f[a[k]][a[j]]=;
  23. }
  24. for (int i=;i<=n;i++)
  25. for (int j=;j<=n;j++)
  26. for (int k=;k<=n;k++)
  27. f[j][k]=std::min(f[j][i]+f[i][k],f[j][k]);
  28. int mn=0x7fffffff;
  29. for (int i=;i<=n;i++){
  30. int s=;
  31. for (int j=;j<=n;j++)
  32. if (i!=j) s+=f[i][j];
  33. if (s<mn) mn=s;
  34. }
  35. mn*=;
  36. mn/=(n-);
  37. printf("%d\n",mn);
  38. }

POJ 2139 Six Degrees of Cowvin Bacon (弗洛伊德最短路)的更多相关文章

  1. AOJ -0189 Convenient Location && poj 2139 Six Degrees of Cowvin Bacon (floyed求任意两点间的最短路)

    http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=78207 看懂题就好. 求某一办公室到其他办公室的最短距离. 多组输入,n表示 ...

  2. POJ 2139 Six Degrees of Cowvin Bacon (floyd)

    Six Degrees of Cowvin Bacon Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 131072/65536K (Ja ...

  3. <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 ...

  4. 任意两点间最短距离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 ...

  5. POJ 2139 Six Degrees of Cowvin Bacon

    水题,Floyd. #include<cstdio> #include<cstring> #include<algorithm> using namespace s ...

  6. POJ 2139 Six Degrees of Cowvin Bacon (Floyd)

    题意:如果两头牛在同一部电影中出现过,那么这两头牛的度就为1, 如果这两头牛a,b没有在同一部电影中出现过,但a,b分别与c在同一部电影中出现过,那么a,b的度为2.以此类推,a与b之间有n头媒介牛, ...

  7. POJ:2139-Six Degrees of Cowvin Bacon

    传送门:http://poj.org/problem?id=2139 Six Degrees of Cowvin Bacon Time Limit: 1000MS Memory Limit: 6553 ...

  8. 【POJ - 2139】Six Degrees of Cowvin Bacon (Floyd算法求最短路)

    Six Degrees of Cowvin Bacon Descriptions 数学课上,WNJXYK忽然发现人缘也是可以被量化的,我们用一个人到其他所有人的平均距离来量化计算. 在这里定义人与人的 ...

  9. 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 ...

随机推荐

  1. url编码模块

    use LWP::SImple; use URI::Escape; encoded_string = uri_escape(raw_string); get(encoded_string);

  2. js 验证ip列表

    如题. <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title ...

  3. centos 挂在ntfs

    Installing build-essentials in CentOS (make, gcc, gdb):http://www.techblogistech.com/2012/03/install ...

  4. Centos_Lvm_Create pv vg lv and mount

    re-scan new disks without restarting CentOS re-scan new disks(/dev/sdc): #ls /sys/class/scsi_host/ h ...

  5. Tomcat+Apache 负载均衡

    1.JDK1.8和Tomcat7.0不兼容,支持Tomcat8.0. 集群架构图: 2.负载均衡:负载的基础是集群,集群就是一组连在一起的计算机,从外部看它是一个系统,各节点可以是不同的操作系统或不同 ...

  6. hihocoder 1145 : 幻想乡的日常

    #1145 : 幻想乡的日常 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 幻想乡一共有n处居所,编号从1到n.这些居所被n-1条边连起来,形成了一个树形的结构. 每处 ...

  7. hdu 2768(建图,最大点独立集)

    Cat vs. Dog Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  8. Android studio 导入工程 出现错误

    原文:http://blog.csdn.net/qazzxc111/article/details/48787419 对于刚开始使用Android studio 并且以前不了解gradle,IDE之类 ...

  9. manacher算法求最长回文子串

    一:背景 给定一个字符串,求出其最长回文子串.例如: s="abcd",最长回文长度为 1: s="ababa",最长回文长度为 5: s="abcc ...

  10. str 编码

    你需要的是让编码用实际编码而不是 ascii    1 对需要 str->unicode 的代码,可以在前边写上  import sys  reload(sys)  sys.setdefault ...