【题目链接】:http://poj.org/problem?id=1860

【题意】



给你n种货币,m种货币之间的交换信息;

交换信息以

A,B,RA,CA,RB,CB的形式给出;

即A换B的话假设A有x元则换成B就变成(X-CA)*RA

B换成A的话同理;

然后你一开始只有某一种x货币;

问你可不可能通过换货币来获得更多x货币;

即最后又要换回来.

【题解】



可以在做SPFA的最长路的时候判断能不能出现环.

具体的。

只要从x出去了,然后又回来了;

就说明能够在经过某些路径之后这个x又变大了;

任意哪一个x都可以;

因为你可以通过这条路径让x变得无穷大;

那么起点s肯定也能无穷大啦;

判断环的话只要判断一个点是否入队n次就好;



【Number Of WA】



1



【完整代码】

#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
const int N = 110;
const int INF = 0x3f3f3f3f; struct abc
{
int en;
double r,c;
}; int n,m,s,num[N];
bool inq[N];
double dis[N];
vector <abc> G[N];
queue <int> dl; int main()
{
//freopen("F:\\rush.txt","r",stdin);
memset(dis,-INF,sizeof dis);
cin >> n >> m >> s;cin >> dis[s];
for (int i = 1;i <= m;i++)
{
int x,y;
double r,c;
abc temp;
cin >>x >> y >> r >> c;
temp.r = r,temp.c = c,temp.en = y;
G[x].push_back(temp);
cin >> r >> c;
temp.r = r,temp.c = c,temp.en = x;
G[y].push_back(temp);
}
dl.push(s);
num[s]=1;
inq[s] = true;
while (!dl.empty())
{
int x = dl.front();
inq[x] = false;
dl.pop();
int len = G[x].size();
for (int i = 0;i <= len-1;i++)
{
abc temp1 = G[x][i];
int y = temp1.en;
double ju = (dis[x]-temp1.c)*temp1.r;
if (ju>0)
{
if (dis[y]<ju)
{
dis[y] = ju;
if (!inq[y])
{
num[y]++;
if (num[y]>n)
return cout <<"YES"<<endl,0;
dl.push(y);
inq[y]=true;
}
}
}
}
}
cout <<"NO"<<endl;
return 0;
}

【POJ 1860】Currency Exchange的更多相关文章

  1. POJ 1860:Currency Exchange

    Currency Exchange Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22648   Accepted: 818 ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. 【SWUST626】分数分解

    Position: * http://acm.swust.edu.cn/problem/0626/ * List SWUST626 分数分解 List Description Input Output ...

  2. 【Poj1325】Machine Schedule机器调度

    目录 List Description Input Output Sample Input Sample Output HINT Solution Code Position: http://poj. ...

  3. 【Poj3241】Object Clustering

    Position: http://poj.org/problem?id=3241 List Poj3241 Object Clustering List Description Knowledge S ...

  4. KVO中你所不知道的"坑"

      一.什么是 KVO 首先让我们了解一下什么KVO,全称为Key-Value Observing,是iOS中的一种设计模式,用于检测对象的某些属性的实时变化情况并作出响应.键值观察Key-Value ...

  5. E20170620-hm

    dump  n. 垃圾场; 仓库; 无秩序地累积;  vt. 倾倒; 倾销; 丢下,卸下; 摆脱,扔弃; terminate   vt. 结束; 使终结; 解雇; 到达终点站; adj. 结束的; d ...

  6. bzoj4563: [Haoi2016]放棋子(错排+高精)

    4563: [Haoi2016]放棋子 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 387  Solved: 247[Submit][Status] ...

  7. kmp的练习们

    //poj3461 Oulipo //kmp模板 统计子串在母串中的位置 #include<iostream> #include<cstdio> #include<cst ...

  8. python之 文件操作

    一.初识文件操作 使用python来读写文件是非常简单的操作,我们使用open函数来打开一个文件,获取到 文件句柄,然后通过文件句柄就可以进行各种各样的操作,同过打开方式的不同能够执行的 操作也会有相 ...

  9. [转]android 获取 imei号码

    核心代码: Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)) .getDeviceId(); 1.加入权限 在manife ...

  10. [转]五个Linux下用户空间的调试工具

    有几个Linux下的用户空间调试工具和技术,它们用来分析用户空间的问题相当有用.它们是: 'print' 语句 查询 (/proc, /sys 等) 跟踪 (strace/ltrace) Valgri ...