解题思路:
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. Maven导入时,Cannot change version of project facet Dynamic Web Module to 3.0.

    今天手贱,在eclipse里面把项目删掉了,重新maven导入时,报出Cannot change version of project facet Dynamic Web Module to 3.0. ...

  2. javaweb学习路之一--web项目搭建

    概述: 工作闲暇时间想要自己搭建一个web项目玩玩,没想到大半天才弄了一个springMVC+mybatis的网站,简直菜的不行,以下记录所有的步骤加深印象 使用环境 1.jdk1.8 2.maven ...

  3. BCS--使用SharePoint Designer创建外部内容类型

    使用SharePoint Designer创建外部列表(也可以在浏览器中创建列表) http://www.cnblogs.com/haogj/archive/2011/05/01/2033845.ht ...

  4. 解决centos7安装wmwaretools找不到kernel header

    解决centos6安装wmwaretools找不到kernel header http://www.centoscn.com/CentosBug/softbug/2015/0525/5531.html ...

  5. STL之stack(栈)

    栈(statck)这种数据结构在计算机中是相当出名的.栈中的数据是先进后出的(First In Last Out, FILO).栈只有一个出口,允许新增元素(只能在栈顶上增加).移出元素(只能移出栈顶 ...

  6. 调试带有源代码的DLL文件

    工作环境:dll源代码是c,在Visual studio 2010中调试. 第一步,调试的准备. 用C#语言编写一个测试dll文件的程序,由于dll源程序是c的,且运行结果是黑屏的,所以C#代码也是运 ...

  7. Zend Studio 如何配置本地apache服务器使用xdebug调试php脚本

    本地环境搭配: apache 2.2 安装位置:D:/program files/Apache Software Foundation/Apache2.2 php 5.2.10 安装位置:C:/php ...

  8. cookie保存分页参数

    <script src="../Public/js/jquery.cookie.js"></script> <script type="te ...

  9. Linux常用解压文件

    tar.gz    tar -zxvf filename.tar.gz tar.bz2  tar -vxjf filename.tar.bz2

  10. QT实现窗口缩放打开与关闭(重叠窗口,太有意思了)

    基本思想:假设A为主窗口,B为子窗口.A打开或关闭时,先对A窗口进行截图,然后将图片部满整个B窗口的,在paintEvent里面进行动态缩放或放大画图.最后使用动画,将B窗口以动画的形式打开或关闭,动 ...