POJ2139 Six Degrees of Cowvin Bacon 最短路
来源:互联网 发布:ios9.3.2越狱软件源 编辑:程序博客网 时间:2024/05/08 07:00
这题水题,就是将出现在同一电影的牛两两连上一个权为1的边,然后询问任意两头牛之间的“距离”。这里直接用的是floyd求最短路。
#ifndef HEAD#include <stdio.h>#include <vector>#include <math.h>#include <string.h>#include <string>#include <iostream>#include <queue>#include <list>#include <algorithm>#include <stack>#include <map>using namespace std;#endif // !HEAD#ifndef QUADMEMSETinline void QuadMemSet(void* dst, int iSize, int value){iSize = iSize / 4;int* newDst = (int*)dst;#ifdef WIN32__asm{mov edi, dstmov ecx, iSizemov eax, valuerep stosd}#elsefor (int i = 0; i < iSize; i++){newDst[i] = value;}#endif}#endifint Dis[301][301];void Flyod(int N){for (int k = 1; k <= N;k++){for (int i = 1; i <= N;i++){for (int j = 1; j <= N;j++){Dis[i][j] = min(Dis[i][j], Dis[i][k] + Dis[k][j]);}}}}int main(){#ifdef _DEBUGfreopen("d:\\in.txt", "r", stdin);#endifint N, M;vector<int> tmp;scanf("%d %d\n", &N, &M);QuadMemSet(Dis, sizeof(Dis), 10000000);for (int i = 0; i < M;i++){int c;tmp.clear();scanf("%d", &c);tmp.resize(c);for (int j = 0; j < c;j++){scanf("%d", &tmp[j]);}for (int j = 0; j < c;j++){for (int h = 0; h < c;h++){if (tmp[j] == tmp[h]){Dis[tmp[j]][tmp[j]] = 0;}else{Dis[tmp[h]][tmp[j]] = 1;Dis[tmp[j]][tmp[h]] = 1;}}}}Flyod(N);int imin = 1000000;for (int i = 1; i <= N;i++){int sum = 0;for (int j = 1; j <= N;j++){if (i == j){continue;}sum += Dis[i][j];}if (imin > sum){imin = sum;}}printf("%d\n", imin * 100 / (N - 1));return 1;}
0 0
- POJ2139 Six Degrees of Cowvin Bacon 最短路
- poj2139 Six Degrees of Cowvin Bacon最短路问题
- POJ2139 Six Degrees of Cowvin Bacon [Floyd]
- POJ2139 Six Degrees of Cowvin Bacon 【Floyd】
- poj2139 Six Degrees of Cowvin Bacon(Flyod)
- POJ2139--Six Degrees of Cowvin Bacon
- POJ2139-Six Degrees of Cowvin Bacon
- POJ2139 Six Degrees of Cowvin Bacon
- POJ2139-Six Degrees of Cowvin Bacon
- poj 2139 Six Degrees of Cowvin Bacon 最短路
- POJ 2139-Six Degrees of Cowvin Bacon(最短路Floyd)
- Six Degrees of Cowvin Bacon (poj 2139 最短路Floyd)
- POJ 2139 Six Degrees of Cowvin Bacon(最短路)
- Six Degrees of Cowvin Bacon(最短路)
- POJ 2139 Six Degrees of Cowvin Bacon 最短路
- POJ 2139 Six Degrees of Cowvin Bacon Floyd最短路
- Six Degrees of Cowvin Bacon (最短路)
- POJ2139 Six Degrees of Cowvin Bacon (Floyd 最短路径)
- SOJ1824: The Suspects
- Win7 下的WiFi共享功能(win7自带)
- C++面试题:介绍一下STL,具体说明STL如何实现vector。
- floyd算法
- mongodb的副本集脑裂情况
- POJ2139 Six Degrees of Cowvin Bacon 最短路
- getopt函数
- boj409.数的关系(高精度java模板)
- 编程算法 - 求1+2+...+n(构造函数) 代码(C++)
- 本博客迁移到Github,之后停止更新
- 谈谈下午的员工入职培训
- 时间序列预测
- UVA How Big Is It?
- QT unicode编码转汉字