标签:取整 iostream i++ inf ble double name content else
水题,随手敲过
一看就是最短路问题,a,b演同一场电影则他们的距离为1
默认全部两两原始距离无穷,到自身为0
输入全部数据处理后floyd
然后照它说的求平均分离度
再找最小的,×100取整输出
#include <cstdio> #include <algorithm> #include <iostream> using namespace std; int cownum,filmnum; int film[11111][333]; int g[333][333]; int inf=(1<<30)-1; int main() { scanf("%d%d",&cownum,&filmnum); for(int i=1;i<=cownum;i++) { for(int j=1;j<=cownum;j++) { if(i==j) g[i][j]=0; else g[i][j]=inf; } } for(int i=1;i<=filmnum;i++) { int everyfilmcownum; scanf("%d",&everyfilmcownum); for(int j=1;j<=everyfilmcownum;j++) { scanf("%d",&film[i][j]); } for(int ii=1;ii<=everyfilmcownum;ii++) { for(int jj=1;jj<=everyfilmcownum;jj++) { int a=film[i][ii]; int b=film[i][jj]; if(ii!=jj) g[a][b]=1; } } } for(int i=1;i<=cownum;i++) for(int j=1;j<=cownum;j++) for(int k=1;k<=cownum;k++) if(g[i][j]>g[i][k]+g[k][j]) g[i][j]=g[i][k]+g[k][j]; double minn=9999999; for(int i=1;i<=cownum;i++) { double res=0; for(int j=1;j<=cownum;j++) { res+=g[i][j]; } res/=cownum-1; minn=min(minn,res); } printf("%d\n",int(minn*100)); }
POJ2139 Six Degrees of Cowvin Bacon [Floyd]
标签:取整 iostream i++ inf ble double name content else
原文地址:http://www.cnblogs.com/lxjshuju/p/6772497.html