您的位置:首页 > 其它

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string