Currency Exchange POJ - 1860 (spfa)
题目链接: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)的更多相关文章
- Currency Exchange POJ - 1860 spfa判断正环
//spfa 判断正环 #include<iostream> #include<queue> #include<cstring> using namespace s ...
- (最短路 SPFA)Currency Exchange -- poj -- 1860
链接: http://poj.org/problem?id=1860 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 2326 ...
- Currency Exchange POJ - 1860 (spfa判断正环)
Several currency exchange points are working in our city. Let us suppose that each point specializes ...
- Currency Exchange - poj 1860
Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 22111 Accepted: 7986 Description Seve ...
- kuangbin专题专题四 Currency Exchange POJ - 1860
题目链接:https://vjudge.net/problem/POJ-1860 大致题意:有不同的货币,有很多货币交换点,每个货币交换点只能两种货币相互交换,有佣金C,汇率R. 每次交换算一次操作, ...
- Currency Exchange 货币兑换 Bellman-Ford SPFA 判正权回路
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- poj - 1860 Currency Exchange Bellman-Ford 判断正环
Currency Exchange POJ - 1860 题意: 有许多货币兑换点,每个兑换点仅支持两种货币的兑换,兑换有相应的汇率和手续费.你有s这个货币 V 个,问是否能通过合理地兑换货币,使得你 ...
- POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环)
POJ 1860 Currency Exchange / ZOJ 1544 Currency Exchange (最短路径相关,spfa求环) Description Several currency ...
- POJ 1860——Currency Exchange——————【最短路、SPFA判正环】
Currency Exchange Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- 转:winform 安装包(很详细)
winform安装项目.安装包的制作.部署 ① 1,解决方案—添加—新建项目—其他项目类型—安装和部署—安装项目,输入名称Setup,点“确定” 2,添加主输出:单击左侧“应用程序文件夹”,右侧右键— ...
- AllowOverride以及Options相关指令
AllowOverride以及Options相关指令 httpd.conf是Apache的主要配置文件,但是针对每个目录,apache还允许在它们各自的目录下放置一个叫做.htacess的文 ...
- Linux学习之路-2017/12/25
三章 命令通配符 .PATH变量 支持多种文本的通配符 通配符 含义 * 匹配零个或多个字符 ? 匹配任意单个字符 [0-9] 匹配范围内的数字 [ ...
- 【原创】由于python的导入方式引起的深坑
目录结构: test/ sacc/ __init__.py app.py logger.py /views __init__.py main.py 事情是这样的,logger里面是一个类LoggerF ...
- 使用C#操作Oracle Spatial的SDO_GEOMETRY对像(读取和写入)
首先,这个需要使用ODAC,也就是Oracle.DataAccess.dll,新出的托管Oracle.ManagedDataAccess.dll不支持Object Type,无法使用 ODAC下载地址 ...
- 【转】PHP面试题总结
PHP面试总结 PHP基础 1:变量的传值与引用. 2:变量的类型转换和判断类型方法. 3:php运算符优先级,一般是写出运算符的运算结果. 4:PHP中函数传参,闭包,判断输出的echo,print ...
- memcached/memcache安装
memcached安装 查找memcached: yum search memcached安装 memcached yum -y install memca ...
- Linux服务器上安装JDK小白教程
一.环境 VMware12 Pro CentOS-6.7-i386-bin-DVD1 jdk-8u151-linux-i586 二.详细安装步骤 前提:需要卸载自己Linux上的jdk rpm -qa ...
- [原创]关于在VS解决方案下使用文件夹管理多个项目层次关系的说明
由于所创建的应用项目或类库项目较多,于是将这些类库放到一个文件夹下.在VS解决方案下确实能看到一个文件夹下多个类库项目这种层次关系.如下图所示: 但打开“我的电脑”,看到的只有类库,并未看到维护层次关 ...
- (转)LR性能测试结果样例分析
原文作者:猥琐丶欲为 传送门:http://www.cnblogs.com/hyzhou/archive/2011/11/16/2251316.html 测试结果分析 LoadRunner性能测试结果 ...