题目链接:Currency Exchange

题意:

  钱的种类为N,M条命令,拥有种类为S这类钱的数目为V,命令为将a换成b,剩下的四个数为a对b的汇率和a换成b的税,b对a的汇率和b换成a的税,公式为(钱数-税)*汇率,问最后钱的数目是否会增多

题解:

  这是我第一道SPFA,这题算是SPFA的模板题吧。找令价值最大的最长路径。

 #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
typedef pair<int,int> P;
const int MAX_N = 1e3+;
struct node{
int to;
double huilv,shui;
node(int a,double b,double c){
to = a;
huilv = b;
shui = c;
}
};
vector<node> vec[MAX_N];
double res[MAX_N];
int vis[MAX_N];
queue< int> que;
int N,M,T,nick;
int a,b;
double huilv1,huilv2;
double shui1,shui2;
double val;
void init()
{
memset(res,,sizeof(res));
memset(vis,,sizeof(vis));
while(!que.empty()) que.pop();
for(int i=;i<MAX_N;i++) vec[i].clear();
}
int spfa(int x)
{
res[x] = val;
vis[x] = ;
que.push(x);
while(!que.empty())
{
int t = que.front();
que.pop();
vis[t] = ;
for(int i=;i<vec[t].size();i++)
{
node temp = vec[t][i]; //if(temp.to == 1) cout<<temp.to<<" "<<temp.huilv<<" "<<temp.shui<<endl; if(res[temp.to] < (res[t] - temp.shui)*temp.huilv)
{
res[temp.to] = (res[t] - temp.shui)*temp.huilv;
if(vis[temp.to] == )
{
que.push(temp.to);
vis[temp.to] = ;
}
}
if(res[x] > val)
return ;
} }
//cout<<"......."<<res[2]<<endl;
return ;
}
int main()
{
while(~scanf("%d%d%d%lf",&N,&M,&nick,&val))
{
init();
for(int i=;i<M;i++)
{
scanf("%d%d%lf%lf%lf%lf",&a,&b,&huilv1,&shui1,&huilv2,&shui2);
vec[a].push_back(node(b,huilv1,shui1));
vec[b].push_back(node(a,huilv2,shui2));
}
if(spfa(nick))
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
return ;
}

  

Currency Exchange POJ - 1860 (spfa)的更多相关文章

  1. Currency Exchange POJ - 1860 spfa判断正环

    //spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...

  2. (最短路 SPFA)Currency Exchange -- poj -- 1860

    链接: http://poj.org/problem?id=1860 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 2326 ...

  3. Currency Exchange POJ - 1860 (spfa判断正环)

    Several currency exchange points are working in our city. Let us suppose that each point specializes ...

  4. Currency Exchange - poj 1860

    Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 22111   Accepted: 7986 Description Seve ...

  5. kuangbin专题专题四 Currency Exchange POJ - 1860

    题目链接:https://vjudge.net/problem/POJ-1860 大致题意:有不同的货币,有很多货币交换点,每个货币交换点只能两种货币相互交换,有佣金C,汇率R. 每次交换算一次操作, ...

  6. Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路

    Description Several currency exchange points are working in our city. Let us suppose that each point ...

  7. poj - 1860 Currency Exchange Bellman-Ford 判断正环

    Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...

  8. POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)

    POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...

  9. POJ 1860——Currency Exchange——————【最短路、SPFA判正环】

    Currency Exchange Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. word问题

  2. iOS7中UIView的animateKeyframesWithDuration方法讲解

    iOS7中UIView的animateKeyframesWithDuration方法讲解 在iOS7中,给UIView添加了一个方法用来直接使用关键帧动画而不用借助CoreAnimation来实现,那 ...

  3. centos安装epel源后,使用报错(Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify its path and try again)

    报错如下: Error: Cannot retrieve repository metadata (repomd.xml) for repository: epel. Please verify it ...

  4. BlockingQueue笔记

    Concurrent包中的BlockingQueue很好的解决了多线程中如何高效安全“传输”数据的问题.通过这些高效并且线程安全的队列类,为我们快速搭建高质量的多线程程序带来极大的便利. 通过一个共享 ...

  5. 【接口】常见接口集合(返回JSON)

    转<JSON校验网站…>http://www.bejson.com/go.html?u=http://www.bejson.com/webInterface.html 这里为大家搜集了一些 ...

  6. Elementary Sorts

    初级排序 rules of the game 排序是很常见的需求,把数字从小到大排,把字符串按字典序排等等,目标是能对任何类型的数据进行排序,这可以通过回调(callback)实现: Java 用接口 ...

  7. 学习HTTP

    http://blog.csdn.net/lmh12506/article/details/7794512 HTTP协议是无状态的和Connection: keep-alive的区别 http协议是无 ...

  8. BZOJ3786:星系探索(Splay,括号序)

    Description 物理学家小C的研究正遇到某个瓶颈. 他正在研究的是一个星系,这个星系中有n个星球,其中有一个主星球(方便起见我们默认其为1号星球),其余的所有星球均有且仅有一个依赖星球.主星球 ...

  9. 【洛谷】【堆+贪心】P1484 种树

    [题目描述:] cyrcyr今天在种树,他在一条直线上挖了n个坑.这n个坑都可以种树,但为了保证每一棵树都有充足的养料,cyrcyr不会在相邻的两个坑中种树.而且由于cyrcyr的树种不够,他至多会种 ...

  10. mysql报错:/usr/sbin/mysqld:unknown variable 'default-character-set=utf8'

    修改mysql的字符集时,为了将默认字符集设置为utf-8,便将/etc/my.cnf下[mysqld]加了一行 default-character-set=utf8, 但是在下次启动系统的时候,my ...