poj1860 currency exchange(1)
来源:互联网 发布:淘宝网商城女装针织衫 编辑:程序博客网 时间:2024/06/05 22:51
1.又犯了和上一次一模一样的错误,没有把freopen()去掉,WA了一次,
2.将每一种货币所能兑换到的金额视为每一个顶点,每一轮货币交换后,若存在至少一个顶点的金额增加,则存在正权回路使该顶点的金额能无限增加,当该点的金额增加到一定数目时,该点货币兑换为初始顶点的货币金额将会大于原始金额。
3.题目的意思看不懂?用谷歌翻译吧!
#include <span style="font-family: Arial, Helvetica, sans-serif;"><iostream></span>
#include <cstring>#include <cstdio>using namespace std;float allkinds_money[210];int currencies,points,kinds;float sum;struct exch{ int begin; int end; float rate; float commission;}exchange[210];bool change_cur(int i){ float a=(allkinds_money[exchange[i].begin]-exchange[i].commission)*exchange[i].rate; if(a>allkinds_money[exchange[i].end]) { allkinds_money[exchange[i].end]=a; return true; } else return false;}bool go_exchange(){ int i,j,k; bool flag; allkinds_money[kinds]=sum; do { flag=false; //这里给flag赋值false,避免当不存在正权回路时do-while无限循环 for(i=1;i<=2*points;i++) { if(change_cur(i)) { flag=true; //cout<<i; } } if(allkinds_money[kinds]>sum) return true; }while(flag); return false;}int main(){ //freopen("D:\input.txt","r",stdin); //freopen("D:\output.txt","w",stdout); bool increase; int i,j,a,b; float r1,c1,r2,c2; while(cin>>currencies>>points>>kinds>>sum) { j=1; memset(allkinds_money,0,sizeof(allkinds_money)); for(i=1;i<=points;i++) { cin>>a>>b>>r1>>c1>>r2>>c2; exchange[j].begin=a; exchange[j].end=b; exchange[j].rate=r1; exchange[j++].commission=c1; exchange[j].begin=b; exchange[j].end=a; exchange[j].rate=r2; exchange[j++].commission=c2; //先前没有换成j++,所以导致循环后j少加了一次 } increase=go_exchange(); if(increase) { cout<<"YES"; } else cout<<"NO"; } return 0;}
0 0
- poj1860 currency exchange(1)
- 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
- Sphinx到Coreseek安装全解
- 算法设计与分析——第二篇,论算法与数据结构的使用方法及技巧
- 深度增强学习Deep Reinforcement Learning (DQN方面)
- HTML+CSS基础 a标签出现重名的a标签,以实现达到当前页面的最底部与达到当前页面的顶端的代码举例
- Find the Duplicate Number
- poj1860 currency exchange(1)
- 今天复习到滚动特性,没想到,这么高大上,<marquee>,其实就是滚动条
- linux shell(leetcode)
- python学习之 beautifulsoup选择器
- Widget的点击事件
- unity-unet-动态spawn player
- LCIS
- Java与模式之建造者模式详解
- Android逆向初步