解题思路:
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. js静态方法和实例方法

    js静态方法 function foo(){} // 声明类 foo.method = function(){} // 方法体 使用:foo.method() js实例方法 function foo( ...

  2. bootstrap固定响应式导航

    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap. ...

  3. C# 日期格式转换 string类型 20150329 转换为 2015/03/29

    DateTime.ParseExact("20150329", "yyyyMMdd", System.Globalization.CultureInfo.Cur ...

  4. Enze Third day(c#中选择结构【if...else】)

    哈喽,又到了我总结课堂知识的时间了.今天在云和学院学的是C#中的“选择结构”下的If语句.下面就来总结一下今天所学的吧. 理论:If语句是最常用的选择结构语句.它主要根据所给定的条件(常由关系表达式和 ...

  5. BZOJ 1827: [Usaco2010 Mar]gather 奶牛大集会( dp + dfs )

    选取任意一个点为root , size[ x ] 表示以 x 为根的子树的奶牛数 , dp一次计算出size[ ] && 选 root 为集会地点的不方便程度 . 考虑集会地点由 x ...

  6. ibatis缓存配置

    一.sqlmapconfig.xml <sqlMapConfig> <settings useStatementNamespaces="true"  cacheM ...

  7. Oracle语句优化规则(二)

    21.       用EXISTS替换DISTINCT 当提交一个包含一对多表信息(比如部门表和雇员表)的查询时,避免在SELECT子句中使用DISTINCT. 一般可以考虑用EXIST替换  例如: ...

  8. (C)单链表

    老师版 #include <stdio.h> #include <stdlib.h> // 定于Node数据类型 struct Node { int data; // 数据域 ...

  9. python yaml使用

    YAML Ain't Markup Language 和GNU一样,YAML是一个递归着说“不”的名字.不同的是,GNU对UNIX说不,YAML说不的对象是XML. YAML不是XML. 为什么不是X ...

  10. asp.net将object或string转为int

    在C#强制转换中,(int),Int32.Parse() 和 Convert.toInt32() 三种方法有何区别? int 关键字表示一种整型,是32位的,它的 .NET Framework 类型为 ...