( ̄▽ ̄)"

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
using namespace std; const int MAXN=40;
int n,m;
double Vcur[MAXN],R[MAXN][MAXN];
bool vis[MAXN];
int cntNode[MAXN];
char ss[MAXN][100]; bool SPFA(int st)
{
queue<int> que;
int u,v; for(int i=1;i<=n;i++)
Vcur[i]=0,vis[i]=0,cntNode[i]=0;
Vcur[st]=1000.0;vis[st]=1;cntNode[st]=1;
que.push(st); while(!que.empty())
{
u=que.front();que.pop();
vis[u]=0; for(v=1;v<=n;v++)
{
if(Vcur[u]*R[u][v]>Vcur[v])
{
Vcur[v]=Vcur[u]*R[u][v];
if(!vis[v])
{
vis[v]=1;
++cntNode[v];
que.push(v);
if(cntNode[v]>=n)
return true;
}
}
}
}
return false;
} int Find(char s[])
{
for(int i=1;i<=n;i++)
if(strcmp(s,ss[i])==0)
return i;
} int main()
{
int Case=0;
while(scanf("%d",&n)&&n)
{
memset(R,0,sizeof(R));
Case++;
for(int i=1;i<=n;i++)
scanf("%s",ss[i]);
scanf("%d",&m);
while(m--)
{
char s1[100],s2[100];
double rate;
scanf("%s",s1);
scanf("%lf",&rate);
scanf("%s",s2);
int u=Find(s1),v=Find(s2);
R[u][v]=rate;
}
int k;
for(k=1;k<=n;k++)
{
if(SPFA(k))
break;
}
if(k>n) printf("Case %d: No\n",Case);
else printf("Case %d: Yes\n",Case);
}
return 0;
}

POJ 2240 Arbitrage(SPFA+邻接矩阵)的更多相关文章

  1. POJ 2240 Arbitrage (spfa判环)

    Arbitrage Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of ...

  2. POJ 2240 Arbitrage spfa 判正环

    d[i]代表从起点出发可以获得最多的钱数,松弛是d[v]=r*d[u],求最长路,看有没有正环 然后这题输入有毒,千万别用cin 因为是大输入,组数比较多,然后找字符串用strcmp就好,千万不要用m ...

  3. POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环)

    POJ 2240 Arbitrage / ZOJ 1092 Arbitrage / HDU 1217 Arbitrage / SPOJ Arbitrage(图论,环) Description Arbi ...

  4. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

    题目传送门 /* 最短路:Floyd模板题 只要把+改为*就ok了,热闹后判断d[i][i]是否大于1 文件输入的ONLINE_JUDGE少写了个_,WA了N遍:) */ #include <c ...

  5. poj 2240 Arbitrage 题解

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 21300   Accepted: 9079 Descri ...

  6. poj 2240 Arbitrage (Floyd)

    链接:poj 2240 题意:首先给出N中货币,然后给出了这N种货币之间的兑换的兑换率. 如 USDollar 0.5 BritishPound 表示 :1 USDollar兑换成0.5 Britis ...

  7. (简单) POJ 2240 Arbitrage,SPFA。

    Description Arbitrage is the use of discrepancies in currency exchange rates to transform one unit o ...

  8. POJ 2240 Arbitrage【Bellman_ford坑】

    链接: http://poj.org/problem?id=2240 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22010#probl ...

  9. poj 2240 Arbitrage bellman-ford算法

    点击打开链接 Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13434   Accepted: 5657 ...

随机推荐

  1. 【01背包】HDU 2602 Bone Collector (模板题)

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...

  2. 图片,音频资源预加载和文档dom加载

    在项目中遇到一个问题,ajax请求音频资源,然后动态的插入到文档中,其中.原生的音频外观实在太丑了,而且每个浏览器的样式都不一样,采取了一个audio插件. 就遇到一个问题,请求后的直接调用插件的话, ...

  3. 希腊字母、拉丁字母、Markdown、拼写与读音中英对照表

    大写 小写 中文名 英文 大写Markdown 小写Markdown 意义 阿尔法 Alpha A \alpha 角度.系数.角加速度.第一个.电离度.转化率 贝塔/毕塔 Beta B \beta 磁 ...

  4. 又遇Release编译的一坑 -- 应用程序正常初始化(0xc000007b)失败。请单击“确定”,终止应用程序。

    项目中使用了xlslib库,以动态库形式编译,由于它没有生成链接库lib文件,所以官方提供的demo中有createDLL这个小程序用来生成lib文件.然而我又 no zuo no die了一次.   ...

  5. intellij 出现“Usage of API documented as @since 1.6+”的解决办法

    Usage of API documented as @since 1.6+ This inspection finds all usages of methods that have @since ...

  6. NMON监控工具

    工具可将服务器的系统资源耗用情况收集起来并输出一个特定的文件,并可利用 excel 分析工具nmonanalyser进行数据的统计分析.并且,nmon运行不会占用过多的系统资源,通常情况下CPU利用率 ...

  7. line-height属性详解

    line-height属性详解:http://www.cnblogs.com/dolphinX/p/3236686.html

  8. 变形属性 transform

    transform功能可以实现文字或图像的旋转.绽放.倾斜.与移动: 注意点:1.其移动.旋转.倾斜.与绽放这4种效果的使用先后顺序不同,页面会显示不同的结果: 2.属性值有一个参数与有多个参数的别: ...

  9. easyui datagrid分页

    datagrid分页设置 pagination="true" 貌似是不行的!  只是显示分页工具栏 没有达到分页效果 前端 $(function (){ var p = $('#d ...

  10. css中position中的几个属性

    static  是默认值.任意 position: static; 的元素不会被特殊的定位.一个 static 元素表示它不会被"positioned",一个 position 属 ...