( ̄▽ ̄)"

#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. 【NOIP2013】Day2不完全题解+代码

    T1 直接递归区间,从1-n开始,找到这个区间中的最小值然后将区间里的所有值都减去这个最小值 以被减去最小值之后的零点为分段分别递归处理即可. #include <algorithm> # ...

  2. Node.js调用百度地图Web服务API的Geocoding接口进行点位反地理信息编码

    (从我的新浪博客上搬来的,做了一些修改.) 最近迷上了node.js以及JavaScript.现在接到一个活,要解析一个出租车点位数据的地理信息.于是就想到使用Node.js调用百度地图API进行解析 ...

  3. wpf ProgressBar使用

    wpf     progressBar使用起来有些麻烦,直接设置value的值还不行 而是通过委托来执行setValue方法 //Create a Delegate that matches the ...

  4. ibatis->mybatis升级过程

    最终目录结构 resources spring applicationContext.xml sqlmap mapper aaamapper.xml bbbmapper.xml mybatis-con ...

  5. 最强DE 战斗力 (nyoj 541)

    题解链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=541 几天前百度题解后用数学知识AC的,后来大牛说这是一道动态规划题. 网上的数学解题链接 ...

  6. 使用 FormsAuthentication 来进行登录验证

    1.在web.config文件中,<system.web>/<authentication>配置节用于对验证进行配置.为<authentication>节点提供mo ...

  7. Fedora24 升级到25

    1 安装dnf-plugin-system-upgrade dnf install dnf-plugin-system-upgrade 2 更新软件包 dnf system-upgrade downl ...

  8. Shell终端收听音乐--网易云音乐命令行版

    Musicbox:网易云音乐命令行版本 高品质网易云音乐命令行版本,简洁优雅,丝般顺滑,基于Python编写. 这款命令行的客户端使用 Python 构建,以 mpg123 作为播放后端: Vim 式 ...

  9. 复习java7 集合的底层实现理解

    1.ArrayList 特点:查询快,增删慢,可以重复,无序 实现:底层是用数组实现的,在添加数据的时候,当数组已经满了,会扩容,默认增加1.5倍的原数组长度,并将旧的数组数据拷贝到新的数组上. 2. ...

  10. linux xfce4普通用户 mount usb提示: Not authorized to perform operation

    问题:xfce4下,USB 硬盘能自动挂载并显示,但是普通用户操作时,提示:Not authorized to perform operation. 时间:20160928 os:gentoo + x ...