解题思路:
1.map简单应用
2.Floyd算法的变形,之后判断dis[i][i],如果大于1,则存在利润!

 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include<map>
using namespace std; map<string,int>name;
const int INF = ;
const int MAXSIZE = ;
const int MAXN = ;
double g[MAXN][MAXN]; //dis[][]记录任意两点间的最短路径,初始的dis[][]记录直接路径
void floyed(double dis[][MAXN],int n){//节点从1~n编号
int i,j,k;
for(k = ; k <= n; k++)
for(i = ; i <= n; i++)
for(j = ; j <= n; j++)
if(dis[i][j] < dis[i][k] * dis[k][j])
dis[i][j] = dis[i][k] * dis[k][j];
}
int main(){
int n,i,m,j;
string str1,str2;
double r;
int iCase = ;
while(scanf("%d",&n),n){
iCase++;
for(i = ; i <= n; i++){
cin>>str1;
name[str1] = i;
}
for(i = ; i <= n; i++)
for(j = ; j <= n; j++){
if(i == j) g[i][j] = ;
else g[i][j] = ;
}
scanf("%d",&m);
while(m--){
cin>>str1>>r>>str2;
g[name[str1]][name[str2]] = r;
} floyed(g,n); bool flag = false;
for(i = ; i <= n; i++){
if(g[i][i] > ){
flag = true;
break;
}
}
if(flag) printf("Case %d: Yes\n",iCase);
else printf("Case %d: No\n",iCase);
}
return ;
}

HDOJ 1217 Floyed Template的更多相关文章

  1. HDOJ 2066 floyed优化算法

    一个人的旅行 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  2. hdu 1217(Floyed)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  3. HDOJ 1217 Arbitrage (最短路)

    题意:每两种货币之间都有不同的汇率  如果换回自己最后是赚的 输出Yes 否则是No 因为最多只有三十种货币 所以用Floyd是可行的 与一般的最短路板子不同的地方 汇率是要乘而不是加 如果乘上一个小 ...

  4. HDOJ 1217 Arbitrage(拟最短路,floyd算法)

    Arbitrage Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  5. [ACM] hdu 1217 Arbitrage (bellman_ford最短路,推断是否有正权回路或Floyed)

    Arbitrage Problem Description Arbitrage is the use of discrepancies in currency exchange rates to tr ...

  6. 【HDOJ】【2829】Lawrence

    DP/四边形不等式 做过POJ 1739 邮局那道题后就很容易写出动规方程: dp[i][j]=min{dp[i-1][k]+w[k+1][j]}(表示前 j 个点分成 i 块的最小代价) $w(l, ...

  7. 【HDOJ】【3068】最长回文

    Manacher算法 Manacher模板题…… //HDOJ 3068 #include<cstdio> #include<cstring> #include<cstd ...

  8. 【HDOJ】【3555】Bomb

    数位DP cxlove基础数位DP第二题 与上题基本相同(其实除了变成long long以外其实更简单了……) //HDOJ 3555 #include<cmath> #include&l ...

  9. 【HDOJ】【4405】Aeroplane chess飞行棋

    概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...

随机推荐

  1. Sql语句之select 5种查询

    select 5种子句:注意顺序where / group by /having / order by / limit / 清空表中的数据:truncate 表名: 导入表结构(不含数据): crea ...

  2. (译)Node.js的模块-exports和module.exports

    原文标题:Node.js Module – exports vs module.exports 原文链接:http://www.hacksparrow.com/node-js-exports-vs-m ...

  3. C#_会员管理系统:开发七(用户分类)

    登录界面(VIPLogin.cs)详细代码: using System; using System.Collections.Generic; using System.ComponentModel; ...

  4. linux下操作gpio寄存器的方法

    一. 在驱动中: 1. 用的时候映射端口:ioremap; #define GPIO_OFT(x) ((x) - 0x56000000) #define GPFCON (*(volatile unsi ...

  5. linkbutton.js

    jquery.linkbutton.js /** * linkbutton - jQuery EasyUI * * Licensed under the GPL: * http://www.gnu.o ...

  6. jquery的链式操作以及事件绑定

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. HTML5 总结-画布-4

    HTML5 画布 创建 Canvas 元素 向 HTML5 页面添加 canvas 元素. 规定元素的 id.宽度和高度: <canvas id="myCanvas" wid ...

  8. [LeetCode]题解(python):062-Unique Paths

    题目来源: https://leetcode.com/problems/unique-paths/ 题意分析: 给定两个整型m,n.判断从一个m×n的矩阵里面,从(0,0)走到(m-1,n-1)一共有 ...

  9. select_related

    作用:减少DB访问次数 from django.db import models class Blog(models.Model): name = models.CharField(max_lengt ...

  10. Linux下gsoap实现webservice功能

    蓝字为关键字,等号=后面为关键字值. 一.介绍 我们用的webservice是根据gsoap编译工具来实现,gSOAP的编译器能够自动的将用户定义的本地化的C或C++数据类型转变为符合XML语法的数据 ...