hdoj1217
2012-02-06 19:48
274 查看
看了别人的思路
#include <climits>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
double w[100][100];
int n,m;
string str[100];
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int M = 0;
while(cin >> n && n)
{
for(int i = 0;i < 100;++i)
{
fill(w[i],w[i]+100,0);
}
fill(str,str+100,string());
for(int i = 0;i < n;++i)
{
cin >> str[i];
}
cin >> m;
for(int i = 0;i < m;++i)
{
string str1,str2;
double weight;
cin >> str1 >> weight >> str2;
int I,J;
for(int j = 0;j < n;++j)
{
if(str[j]==str1)
{
I = j;
break;
}
}
for(int j = 0;j < n;++j)
{
if(str[j] == str2)
{
J = j;
break;
}
}
w[I][J] = weight;
}
for(int i = 0;i < n;++i)
{
for(int j = 0;j < n;++j)
{
for(int k=0;k < n;++k)
{
if(w[j][k] < w[j][i]*w[i][k])
{
w[j][k] = w[j][i]*w[i][k];
}
}
}
}
bool can = false;
for(int i = 0;i < n;++i)
{
if(w[i][i] > 1)
{
can = true;
}
}
if(can)
cout << "Case " << (++M) << ": Yes" << endl;
else
cout << "Case " << (++M) << ": No" << endl;
}
return 0;
}
#include <climits>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
double w[100][100];
int n,m;
string str[100];
int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int M = 0;
while(cin >> n && n)
{
for(int i = 0;i < 100;++i)
{
fill(w[i],w[i]+100,0);
}
fill(str,str+100,string());
for(int i = 0;i < n;++i)
{
cin >> str[i];
}
cin >> m;
for(int i = 0;i < m;++i)
{
string str1,str2;
double weight;
cin >> str1 >> weight >> str2;
int I,J;
for(int j = 0;j < n;++j)
{
if(str[j]==str1)
{
I = j;
break;
}
}
for(int j = 0;j < n;++j)
{
if(str[j] == str2)
{
J = j;
break;
}
}
w[I][J] = weight;
}
for(int i = 0;i < n;++i)
{
for(int j = 0;j < n;++j)
{
for(int k=0;k < n;++k)
{
if(w[j][k] < w[j][i]*w[i][k])
{
w[j][k] = w[j][i]*w[i][k];
}
}
}
}
bool can = false;
for(int i = 0;i < n;++i)
{
if(w[i][i] > 1)
{
can = true;
}
}
if(can)
cout << "Case " << (++M) << ": Yes" << endl;
else
cout << "Case " << (++M) << ": No" << endl;
}
return 0;
}
相关文章推荐
- hdoj 1217 Arbitrage
- hdoj1217
- HDOJ 1217 Arbitrage (最短路 Floyd)
- hdoj 1217 Arbitrage 【最短路径】【floyd】
- HDOJ-1217-Arbitrage 解题报告
- HDOJ 1217 Floyed Template
- HDOJ 1217 Arbitrage
- [HDOJ1217]Arbitrage(floyd)
- hdoj1217 Arbitrage
- HDOJ 题目1217 Arbitrage(最短路径,Floyd)
- HDOJ 1217 Arbirage(最短路)
- HDOJ1217 floyed算法
- HDOJ 1217 Arbitrage 【Floyd 有负权】
- HDU/HDOJ 1217 Arbitrage University of Ulm Local Contest 1996
- hdoj 1217 Arbitrage(floyd+处理名字为字符串的情况)
- HDOJ2053
- Holding Bin-Laden Captive! 【HDOJ-1085-母函数】
- HDOJ 5399.Too Simple(2015多校-9的1004)
- HDOJ 2061 Treasure the new start, freshmen!
- Friend-Graph(hdoj6152)