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 ...
随机推荐
- 转:c# WinForm开发 DataGridView控件的各种操作总结(单元格操作,属性设置)
一.单元格内容的操作 *****// 取得当前单元格内容 Console.WriteLine(DataGridView1.CurrentCell.Value); // 取得当前单元格的列 Index ...
- 新建一个去除storyboard的项目
新建一个去除storyboard的项目 1. 新建项目并删除 *.storyboard 以及与之相关的杂项 2. 设置 UIWindow 的 rootViewController 复制粘贴代码如下 s ...
- Linux 系统的/var目录
/var目录主要针对常态性变动的文件,包括缓存(cache).登录档(log file)以及某些软件运作所产生的文件 /var目录下的重要目录 目录 应放置文件内容 /var/cache/ 应用程序本 ...
- Spring MVC Hello World 404
下面的例子说明了如何使用 Spring MVC 框架来编写一个简单的基于 web 的 Hello World 应用程序.下面让我们使用 Eclipse IDE,然后按照下面的步骤使用 Spring 的 ...
- sharepoint 2013 sp1 patch安装后的手工运行
在安装SP1 后,有时Center admin 会显示 那么必须在以administrator运行sharepoint 2013 powershell. PSConfig.exe -cmd upgra ...
- 用php代码统计数据库中符合条件的行数
$sql1 = "select count(*) from t_user where age<17"; $data1 = mysql_query($sql1); $rows1 ...
- criterions的选择
criterions分为几类,其中有classification criterions与regression criterions.classification criterions是针对离散的,re ...
- php5.6+Apache2.4+MySQL
在配置php的时候可以直接使用集成环境XAMPP:https://bitnami.com/stack/xampp?utm_source=bitnami&utm_medium=installer ...
- Kafka设计解析(三)Kafka High Availability (下)
转载自 技术世界,原文链接 Kafka设计解析(三)- Kafka High Availability (下) 摘要 本文在上篇文章基础上,更加深入讲解了Kafka的HA机制,主要阐述了HA相关各种场 ...
- MapReduce经典入门小案例
/** * 单词统计 * @author fengmingyue * */ public class WordCount { public static void main(String[] args ...