题目链接:Arbitrage

让这题坑了,精度损失的厉害。用赋值的话。直接所有变成0.00了,无奈下,我仅仅好往里输了,和POJ1860一样找正环,代码也差点儿相同,略微改改就能够了,可是这个题精度损失的比那个。

。。。

水过

POJ计划的最短路模块,刷完了,最短路问题,挺坑的,可是就是那点东西,变来变去,就是改改dis[]的更新条件。

明天就要開始POJ的最小生成树了,

ME                  TI

704Kb            46Ms

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 50;
const int M = 1010;
char a[N][N],s[N];
double dis[N];
int n,m,num;
struct node{
int u,v;
double w;
}edge[M];
int Bellman(int x)
{ dis[x] = 1.0;//開始时漏了,结果都打NO
for(int i = 0;i <n;i++)
{
for(int j = 0;j < num; j++)
{
if(dis[edge[j].v] < dis[edge[j].u] * edge[j].w)
dis[edge[j].v] = dis[edge[j].u] * edge[j].w;
}
}
for(int i = 0;i<num;i++)
{
if(dis[edge[i].v] < dis[edge[i].u]*edge[i].w)
return 1;
}
return 0; }
int main()
{
int c;
c = 0;
while(scanf("%d",&n),n)
{
c++;
for(int i = 0;i <n;i++)
dis[i] = 0; for(int i = 0;i <n;i ++)
scanf("%s",a[i]); scanf("%d",&m);
num = 0;
while(m--)
{
scanf("%s",s);
for(int i = 0;i <n;i++)
{
if(strcmp(s,a[i])== 0)
{
edge[num].u = i;
break;
}
}
scanf("%lf",&edge[num].w);
scanf("%s",s);
for(int i = 0;i <n;i++)
{
if(strcmp(s,a[i]) == 0)
{
edge[num++].v = i;
break;
}
}
}
int st;
for(int i = 0;i<n;i++)//挨个枚举,找正环
{
st = Bellman(i);
if(st)
break;
}
printf("Case %d: ",c);
if(st)
puts("Yes");
else
puts("No");
}
return 0;
}

POJ-2240 -Arbitrage(Bellman)的更多相关文章

  1. 最短路(Floyd_Warshall) POJ 2240 Arbitrage

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

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

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

  3. poj 2240 Arbitrage 题解

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

  4. poj 2240 Arbitrage (Floyd)

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

  5. POJ 2240 Arbitrage (Bellman Ford判正环)

    Arbitrage Time Limit: 1000MS   Memory Limit: 65536K Total Submissions:27167   Accepted: 11440 Descri ...

  6. POJ 2240 Arbitrage【Bellman_ford坑】

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

  7. POJ 2240 Arbitrage(判正环)

    http://poj.org/problem?id=2240 题意:货币兑换,判断最否是否能获利. 思路:又是货币兑换题,Belloman-ford和floyd算法都可以的. #include< ...

  8. poj 2240 Arbitrage

    Time Limit: 1000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   Java class name ...

  9. poj 2240 Arbitrage bellman-ford算法

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

  10. POJ 2240 Arbitrage(floyd)

    http://poj.org/problem?id=2240 题意 : 好吧,又是一个换钱的题:套利是利用货币汇率的差异进行的货币转换,例如用1美元购买0.5英镑,1英镑可以购买10法郎,一法郎可以购 ...

随机推荐

  1. Swift详解之NSPredicate

    言:谓词在集合过滤以及CoreData中有着广泛的应用.本文以Playground上的Swift代码为例,讲解如何使用NSPredicate. 准备工作 先在Playground上建立一个数组,为后文 ...

  2. 智能指针unqiue_ptr

    unique_ptr unique_ptr 对它指向的对象在同一时刻是独占的.它要么在构造的时候使用内置指针初始化,要么使用reset给其赋值.当unique_ptr被销毁时,它所指向的对象也被销毁. ...

  3. mysql 报错:ERROR 1418 (HY000): This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA

    解决办法:设置临时环境变量 ;  

  4. C第10章-----通过引用传递

    #include <stdio.h> #include <math.h> void metersToFeetAndInches(double meters,unsigned i ...

  5. LeetCode(77) Combinations

    题目 Given two integers n and k, return all possible combinations of k numbers out of 1 - n. For examp ...

  6. ArrayList练习之存储自定义对象并遍历

    新建一个Student.java类 Student.java /* * 这是一个学生类 */ public class Student { private String name; private i ...

  7. NGINX模块(二)

    [Nginx标准HTTP模块] 一.HTTP核心模块 指令1:alias 语法:alias file-path|directory-path; 默认值:no 使用字段:location 说明:这个指令 ...

  8. 大数据学习——hive安装部署

    1上传压缩包 2 解压 tar -zxvf apache-hive-1.2.1-bin.tar.gz -C apps 3 重命名 mv apache-hive-1.2.1-bin hive 4 设置环 ...

  9. Git上传的使用步骤

    Git上传的使用步骤 首先 git branch 查看当前的分支是否为本地自己分支 接着 git stash 保存本地自己的保存 git checkout earemote 查看本地共有开发分支 gi ...

  10. hud 2073

    #include<stdio.h> #include<math.h> int main() { int i,j,k,n,m,t; double a]; a; for;i++) ...