Arbitrage hdu 1217 最长路Floyd

/*
 一开始题目没有看清楚,题目求的是最长路,而不是最短路
 注释的代码是错的,题目要看清楚
*/


#include <iostream>//2566050 2010-07-02 12:58:09 Accepted 1217 31MS 296K 1755 B C++ 悔惜晟
#include <queue>
#include <cstdio>
#include <map>
#include <string>
#include <cstring>
using namespace std;

map<string, int > hash;
double cost[35][35];
bool hash1[35];
const int MAX = 0x3fffffff;
int n;

void Floyd()//还不是很理解的
{
 for(int i = 1;i <= n; i++){
    for(int j = 1;j <= n; j++){
    for(int k = 1;k <= n; k++){
            if(cost[j][i] * cost[i][k] > cost[j][k])
       cost[j][k] = cost[j][i] * cost[i][k];
        }
    }
}
}
/*
struct node
{
 double mon;
 int h;
 friend bool operator < (node a, node b)
 {
  return a.mon < b.mon;
 }
};

void BFS(string ss)
{
 priority_queue<node> Q;
 node P, N;
 for(int i = 1; i <= n; i++)
 {
  if(cost[hash[ss]][i] != MAX)
  {
   P.h = i;
   P.mon = cost[hash[ss]][i];
   Q.push(P);
  }
 }
 while(!Q.empty())
 {
  P = Q.top();
  Q.pop();
  if(P.h == hash[ss])
  {
   if(P.mon > 1)
    printf("Yes/n");
   else
    printf("No/n");
   return ;
  }
  hash1[P.h] = true;
  for(int i = 1; i <= n; i++)
  {
   if(!hash1[i] && cost[P.h][i] != MAX)
   {
    N.h = i;
    N.mon = P.mon * cost[P.h][i];
    Q.push(N);
   }
  }
 }

}
*/

int main()
{
 int m;
 double dis;
 char s[35], en[35];
 string ss;
 int t = 1;
 //string ss, en;
 while(scanf("%d", &n) != EOF && n)
 {
  for(int i = 1; i <= n; i++)
  {
   scanf("%s", s);
   hash[s] = i;
  }
  ss = s;
  for(int i = 1; i <= n; i++)
  for(int j = 1; j <= n; j++)
   cost[i][j] = 1;
  scanf("%d", &m);
  while(m--)
  {
   scanf("%s %lf %s", s, &dis, en);
   {
    cost[hash[s]][hash[en]] = dis;
   }
  }
  //BFS(ss);
  Floyd();
  if(cost[hash[ss]][hash[ss]] > 1)
  printf("Case %d: Yes/n", t++);
  else
  printf("Case %d: No/n", t++);
 }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值