UVA 538 - Balancing Bank Accounts

题目链接:

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;
}

版权声明:转载请注明出处。

时间: 2024-08-14 02:02:13

UVA 538 - Balancing Bank Accounts的相关文章

UVA 538 - Balancing Bank Accounts(贪心)

UVA 538 - Balancing Bank Accounts 题目链接 题意:给定一些人的欠钱关系,要求在n-1次内还清钱,问方案 思路:贪心,处理出每一个人最后钱的状态,然后直接每一个人都和最后一个人操作就可以 代码: #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <map> using namespace std;

How To Change the Supplier Bank Account Masking in UI (Doc ID 877074.1)

Give Feedback...         How To Change the Supplier Bank Account Masking in UI (Doc ID 877074.1) To Bottom In this Document  Goal  Solution  References APPLIES TO: Oracle Payables - Version: 12.1.0<max_ver> and later   [Release: 12.1 and later ]Info

Global Financial Applications uses the following Public tables

来自文档: Oracle  Financial Applications Technical Reference Manual  更多明细参考文档     Table Name                                                 Description AP_AE_HEADERS_ALL                            Accounting entry headers table (See page 3 – 8

Oracle Global Finanicals Oracle Global Financials Technical Reference(一)

Skip Headers Oracle Global Finanicals Oracle Global Financials Technical Reference Manual Release 11i         Globalization Flexfields This document describes the globalization flexfields that store certain pieces of country- and region-specific info

atitit.Sealink2000国际海运信息管理系统

操作手册 目录 第一章 使用说明 第一节 系统登录 双击桌面的系统执行程序图标,进入选择数据库的对话框,如图1-1所示.选择相应的数据库后,点击[OK]按钮或在所选数据库上双击,进入登录身份校验对话框,如图1-2所示,输入正确的用户名和口令后,点击[OK]按钮,即可进入此系统. 图1-1[进入数据库选择]对话框 图1-2[登录]对话框 第二节 功能模块介绍 1.2.1 基础数据 在系统的『Basic Data』菜单下面的,都是系统基础数据方面的功能设置菜单.主要是系统关于公共的.需要规范的数据的

Java 并发 线程同步

Java 并发 线程同步 @author ixenos 同步 1.异步线程本身包含了执行时需要的数据和方法,不需要外部提供的资源和方法,在执行时也不关心与其并发执行的其他线程的状态和行为 2.然而,大多数实际的多线程应用中,两个或两个以上的线程需要共享对同一数据的存取,这将产生同步问题(可见性和同步性的丢失) 比如两个线程同时执行指令account[to] += amount,这不是原子操作,可能被处理如下: a)将account[to]加载到寄存器 b)增加amount c)将结果写回acco

TPL Part 4 -- Task的协同

简单的Continuation Task.ContinueWith(Task): 当指定的Task执行完毕时. void Main() { Task rootTask = new Task(()=>{ Console.WriteLine("root task completed"); }); root Task.ContinueWith((Task previousTask)=>{ Console.WriteLine("continute task complet

voa 2015 / 4 / 14

Even with falling oil prices and strong U.S. growth, the head of the International Monetary Fund said the global economy only expanded around 3.4 percent last year. While that is near the average growth over the last couple of decades, IMF Managing D

infoq - neo4j graph db

My name is Charles Humble and I am here at QCon New York 2014 with Ian Robinson. Ian, can you introduce yourself to the InfoQ community? Hello, I am Ian Robinson, I am engineer at Neo Technology, I am based in London and I work on the Neo4j graph dat