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 ...
随机推荐
- 使用GTID给Galera集群做数据库异步复制
一.为什么要做Galera集群异步复制 Galera集群解决了数据库高可用的问题,但是存在局限性,例如耗时的事务处理可能会导致集群性能急剧下降,甚至出现阻塞现象.而不幸的是,类似报表等业务需求就需要做 ...
- json格式转换(json,csjon)(天气预报)
json格式数据默认为string,可以使用eval()函数或者json模块将其转换为dict.标准Json字符串必须使用双引号(")而不能使用单引号('),否则从字符串转换成dict类型会 ...
- QT的时区转换以及使用注意事项
QDateTime localDate = QDateTime::fromString("2018-12-11 10:40:00", "yyyy-MM-dd hh:mm: ...
- Windows未能启动:0xc00000e9错误
问题:计算机无法启动,错误代码为:0xc00000e9 解决方法: 1.如报错所示,\Windows\System31\config\system 文件丢失或损坏: 2.如许修复此问题,需在打开此目录 ...
- zabbix日常监控(监控缓存)
实现的方法大体类似: 多谢博主的文章,免了不少时间! 摘抄博文地址:https://www.cnblogs.com/sixiweb/p/6893858.html https://www.cnblogs ...
- 归并排序(php实现)
<?php function mergeSort(&$arr){ $len = count($arr); msort($arr,0,$len-1); } function msort(& ...
- FreeMarker标签使用
FreeMarker标签使用 模板技术在现代的软件开发中有着重要的地位,主要用于view层的展示,freemarker是比较流行的一种. 一.FreeMarker模板文件主要有4个部分组成 ①文本,直 ...
- python第十五课——全局变量and局部变量
全局变量&局部变量: 全局变量的特点: 1).直接定义在.py文件中(函数外)的变量(全局位置) 2).作用域比较大,可以被此文件中的任何函数所使用 局部变量的特点:1).定义在函数内部(函数 ...
- Android Studio3.0 配置AndroidAnnotation注解框架
前言android学习了一段时间后,想要开发一款App,但是一些复杂的代码写多了实在麻烦,就到网上找了找简便的方法,于是在众多的注解开发框架中,找到了Android Annotation这个框架,这里 ...
- cmdb截图