poj 1860 Currency Exchange
来源:互联网 发布:mac 画流程图的软件 编辑:程序博客网 时间:2024/06/14 17:36
dis数组写成int了 神他妈WA一下午…
bellman_ford求正环,人生第一条图论题…
#include <iostream>#define maxn 410#define inf 0x3f3f3f3fstruct edge{ int u, v; double rate, com;}side[maxn];double dis[maxn];int edge_num, node_num, source;double value;void init() { for(int i = 1; i <= edge_num; i++) { dis[i] = 0; } dis[source] = value;}int bellman_ford() { init(); for(int i = 0; i < edge_num; i++) { for(int j = 1; j <= 2 * node_num; j++) { if(dis[side[j].v] < (dis[side[j].u] - side[j].com) * side[j].rate){ dis[side[j].v] = (dis[side[j].u] - side[j].com) * side[j].rate; } } } for(int j = 1; j <= 2 * node_num; j++) { if(dis[side[j].v] < (dis[side[j].u] - side[j].com) * side[j].rate){ return 1; } } return 0; } int main(int argc, char *argv[]) { //std::ios::sync_with_stdio(false); std::cin >> edge_num >> node_num >> source >> value; for(int i = 1; i <= 2 * node_num; i += 2) { //std::cout << "BIU!\n"; std::cin >> side[i].u >> side[i].v >> side[i].rate >> side[i].com >> side[i+1].rate >> side[i+1].com; side[i+1].u = side[i].v; side[i+1].v = side[i].u; } if(bellman_ford()) { std::cout << "YES\n"; } else { std::cout << "NO\n"; } return 0;}
阅读全文
0 0
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- Poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- POJ 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ-1860-Currency Exchange
- POJ 1860 Currency Exchange
- poj 1860 Currency Exchange
- POJ 1860 Currency Exchange
- NPM私服搭建
- ShareSDK分享以及所遇到的一些问题
- 蓝桥杯java第四届决赛第四题--九宫重排
- db2数据库字段操作相关问题
- Linux下xampp集成安装配置
- poj 1860 Currency Exchange
- react整合webpack时,遇到的syntaxerror
- 最小树形图(朱刘算法)
- 分治法解决最大连续和
- iOS学习之路05
- 在CentOS 7中安装与配置JDK8
- unity_LODFade使用总结
- Retrofit2 源码解析
- Python : bp神经网络