UVa11679 - Sub-prime

简介: UVa11679 - Sub-prime
#include <cstdio>#include <cstring>usingnamespacestd;
constintN=21;
intb, n;
intcost[N];
boolinput();
voidsolve();
intmain()
{
#ifndef ONLINE_JUDGEfreopen("d:\\OJ\\uva_in.txt", "r", stdin);
#endifwhile (input()) {
solve();
    }
return0;
}
boolinput()
{
scanf("%d%d", &b, &n);
if (b==0&&n==0) returnfalse;
memset(cost, 0x00, sizeof(cost));
for (inti=1; i<=b; i++) {
scanf("%d", &cost[i]);
    }
for (inti=0; i<n; i++) {
intdebtor, creditor, debenture;
scanf("%d%d%d", &debtor, &creditor, &debenture);
cost[debtor] -=debenture;
cost[creditor] +=debenture;
    }
returntrue;
}
voidsolve()
{
boolok=true;
for (inti=1; i<=b; i++) {
if (cost[i] <0) {
ok=false;
break;
        }
    }
printf("%s\n", ok?"S" : "N");
}
目录
相关文章
UVa10484 - Divisibility of Factors(数论)
UVa10484 - Divisibility of Factors(数论)
71 1
uva167 The Sultan's Successors
uva167 The Sultan's Successors
50 0
uva10783 Odd Sum
uva10783 Odd Sum
54 0
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
HDOJ(HDU) 2136 Largest prime factor(素数筛选)
118 0
|
机器学习/深度学习
|
人工智能 BI 算法
uva 1121 - Subsequence
点击打开链接uva 1121 思路:二分查找 分析: 1 题目要求找到一个最短的子序列长度并且这个子序列的和大于等于给定的s 2 如果按照常规的做法枚举起点和终点的话肯定是会超时的。
935 0