POJ1860 - Currency Exchange
来源:互联网 发布:近年来网络阅读手机 编辑:程序博客网 时间:2024/05/29 19:54
钱币兑换问题,问能否借助兑换货币获取利益,要考虑汇类和手续费。
第一行输入货币种类N,兑换点M(可以双向兑换),现有货币种类,现有货币种类。
之后M行,每行输入6个数,货币a,货币b,a到b的汇率,a到b兑换的手续费,a到b的汇率,b到a兑换的手续费,b到a的汇率。
兑换公式为: b = (a - 手续费)* 汇率。
借助bellman-ford算法判断环的思路解题。
//Memory Time//272K47MS#include<iostream>#include<queue>using namespace std;struct edge{edge* next;int dstVex;float rat;float com;};struct vertex{floatmoney;intdeep;bool isAddInQueue;};vertex vex[101];edge* eg[101];int main(){int N, M, type;float money;cin>>N>>M>>type>>money;for(int i = 1; i<= N; i++){vex[i].money = -1;vex[i].deep = -1;vex[i].isAddInQueue = false;eg[i] = NULL;}vex[type].money = money;vex[type].deep = 1;for(int i = 0; i < M; i++){int src, dst;float rat, com;cin >> src >> dst;cin >> rat >> com;edge* e = new edge;e->next = eg[src];e->dstVex = dst;e->rat = rat;e->com = com;eg[src] = e;cin >> rat >> com;e = new edge;e->next = eg[dst];e->dstVex = src;e->rat = rat;e->com = com;eg[dst] = e;}queue<int> que;vex[type].isAddInQueue = true;que.push(type);int maxDeep = 0;while(!que.empty()){int tempSrc = que.front();vex[tempSrc].isAddInQueue = false;que.pop();edge* e = eg[tempSrc];while(e != NULL){int dstVex = e->dstVex;float tempMoney = vex[tempSrc].money;tempMoney = (tempMoney - e->com) * e->rat;if(tempMoney > vex[dstVex].money){vex[dstVex].money = tempMoney;vex[dstVex].deep = vex[tempSrc].deep + 1;if(vex[dstVex].deep > maxDeep)maxDeep = vex[dstVex].deep;if(vex[dstVex].isAddInQueue == false){que.push(dstVex);vex[dstVex].isAddInQueue == true;}}e = e->next;}if(maxDeep > N)break;}if(maxDeep > N)cout << "YES" << endl;elsecout << "NO" << endl;return 0;}
0 0
- POJ1860:Currency Exchange
- poj1860 - Currency Exchange
- Currency Exchange poj1860
- poj1860--Currency Exchange
- poj1860 Currency Exchange
- poj1860--Currency Exchange
- POJ1860 Currency Exchange
- POJ1860 Currency Exchange
- poj1860--Currency Exchange
- POJ1860-Currency Exchange
- POJ1860 - Currency Exchange
- POJ1860---Currency Exchange
- poj1860 Currency Exchange (bellman_ford)
- poj1860 - Currency Exchange
- 【POJ1860】Currency Exchange
- POJ1860-Currency Exchange
- poj1860 Currency Exchange
- poj1860 currency exchange(1)
- 在Linux下编写Daemon
- 背包问题九讲
- Windows环境下搭建基于CooCox CoIDE的STM32 GCC 开发环境
- 在ARC下 选择使用weak和assign的区别
- Apache ActiveMQ 持久化到MySQL数据库的简单配置
- POJ1860 - Currency Exchange
- 外设与存储器交互方式总结
- leetcode解题笔记-Minimum Window Substring
- 解决500 OOPS: vsftpd: cannot locate user specified in 'ftp_username':ftp的问题
- Java SE 第十讲(面向对象之封装) 续
- 读书笔记——程序员成长的烦恼(吴亮等)
- Eclipse调试Hbase程序“Failed to detect a valid hadoop home directory java.id.IOException”问题
- 再探Objective-C.4
- HDU3639 Hawk-and-Chicken 强连通+缩点+建反向图