UVA 538 - Balancing Bank Accounts
来源:互联网 发布:单片机的32个引脚介绍 编辑:程序博客网 时间:2024/06/05 09:52
题目链接:
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=599&problem=479&mosmsg=Submission+received+with+ID+14105881
题意:
给定一些人的欠钱关系,要求在n-1次内还清钱,问方案
解法:所有人与第n个人结账。计算关系。
代码:
#include <stdio.h>#include <iostream>#include <algorithm>#include <string.h>#include <queue>#include <math.h>#include <map>#include <string>using namespace std;int n, m;map<string, int> Hash;int is[100];string name[100];int main(){ int cases = 1; while (cin >> n >> m) { if (n == 0 && m == 0) break; memset(is, 0, sizeof(is)); Hash.clear(); string s,ss; int tmp; for (int i = 1; i <= n; i++) { cin >> name[i]; Hash[name[i]] = i; } for (int i = 1; i <= m; i++) { cin >> s >> ss >> tmp; is[Hash[s]] += tmp; is[Hash[ss]] -= tmp; } printf("Case #%d\n",cases++); for (int i = 1; i < n; i++) { if (is[i] > 0) cout << name[n] << " " << name[i] << " " << is[i] << endl; else cout << name[i] << " " << name[n] << " " << -is[i] << endl; is[n] -= is[i]; } cout << endl; } return 0;}
0 0
- UVA 538 - Balancing Bank Accounts
- UVA 538 - Balancing Bank Accounts(贪心)
- uva 538 - Balancing Bank Accounts(贪心)
- UVa538 - Balancing Bank Accounts
- R12 TCA BANKS, BRANCHES and Bank Accounts
- UVA 12904 Load Balancing (暴力)
- Balancing
- uva 1381 - Balancing the Scale(枚举+位运算)
- bank
- bank
- bank
- Net accounts
- Managing Accounts
- Accounts(简介)
- List Accounts
- Load Balancing
- Balancing Act
- load balancing
- CF_560A_CurrencySystemInGeraldion
- 接口
- 算法竞赛入门经典(第二版) 习题3-6 Crossword Answers UVa232 Finals1994
- C++类的构造函数和析构函数的调用顺序
- 互联网金融行业全景及展望
- UVA 538 - Balancing Bank Accounts
- 天道酬勤
- 对萍蹈堵钾嚼释锹
- OpenCV学习笔记(1)—— 摄像机模型与标定2
- Linux framebuffer显示bmp图片
- hdu1870(愚人节的礼物)--- 简单栈类
- 互斥锁和条件变量
- 查询优化(一) @2012-06-02
- [BZOJ1861][Zjoi2006]Book 书架