【POJ 1860】Currency Exchange
【题目链接】: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的更多相关文章
- POJ 1860:Currency Exchange
Currency Exchange Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22648 Accepted: 818 ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- SQL 2005批量插入数据的二种方法
SQL 2005批量插入数据的二种方法 Posted on 2010-07-22 18:13 moss_tan_jun 阅读(2635) 评论(2) 编辑 收藏 在SQL Server 中插入一条数据 ...
- 产生冠军(toposort)
http://acm.hdu.edu.cn/showproblem.php?pid=2094 #include <stdio.h> #include <iostream> #i ...
- [App Store Connect帮助]三、管理 App 和版本(2.7)输入 App 信息:添加 iMessage 信息版 App 的 App 信息
您可以使用 Messages framework(Messages 框架)来创建贴纸包或 iMessage 信息版 App(可在 iMessage App Store 中获取).可作为独立 App,也 ...
- [Swift通天遁地]四、网络和线程-(9)上传图片并实时显示上传进度
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- [Swift通天遁地]五、高级扩展-(6)对基本类型:Int、String、Array、Dictionary、Date的扩展
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- zookeeper集群安装及使用详解
1. Zookeeper简介 ZooKeeper是一个开源的分布式框架,提供了协调分布式应用的基本服务.它向外部应用暴露一组通用服务——分布式同步(Distributed Synchronizatio ...
- jmeter中beanshell断言的使用
简单使用beanshell的内容,进行测试内容的判断 这里通过断言内容,修改if的条件,达到发送警报邮件的功能 beanshell 代码如下: SampleResult 等效于 prev lo ...
- BZOJ 2300凸包+离线
思路: 倒着加显然吧 动态维护这个凸包就好了 //By SiriusRen #include <bits/stdc++.h> using namespace std; ; int n,m ...
- WinForm 之 使用ListView控件展示数据
在学习了这么多的WinForm基本控件后,今天在来学习一个比较有意思的包含图片的控件! >>>图像列表控件 ImageList是含有图像对象的集合,可以通过索引或关键字引用该集合中的 ...
- [ SCOI 2005 ] 最大子矩阵
\(\\\) \(Description\) 给出一个\(N\times M\)的有权矩阵,选出其中\(K\)个互不重叠的子矩阵,使得这\(K\)个子矩阵的权值和最大. \(N\in [1,100]\ ...