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");
}
目录
相关文章
HDU-1061,Rightmost Digit(快速幂)
HDU-1061,Rightmost Digit(快速幂)
|
机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
POJ 1775 (ZOJ 2358) Sum of Factorials
122 0
|
机器学习/深度学习 网络架构
题解 UVA10212 【The Last Non-zero Digit.】
题目链接 这题在学长讲完之后和看完题解之后才明白函数怎么构造。这题构造一个$f(n)$$f(n)$ $=$ $n$除以 $2^{a}$ $*$ $5^{b}$ ,$a$ , $b$ 分别是 $n$ 质因数分解后$2,5$的个数。
1206 0
|
安全
D-POJ-3126 Prime Path
Description The ministers of the cabinet were quite upset by the message from the Chief of...
1108 0
|
人工智能 机器学习/深度学习
POJ 1775 (ZOJ 2358) Sum of Factorials
Description John von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions t...
1114 0
容斥 - HDU 4135 Co-prime
Co-prime  Problem's Link:  http://acm.hdu.edu.cn/showproblem.php?pid=4135 推荐: 容斥原理 Mean:  给你一个区间[l,r]和一个数n,求[l,r]中有多少个数与n互素。
888 0
|
机器学习/深度学习 并行计算 Java
hdu 4135 Co-prime【容斥原理】
Co-prime Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1668    Accepted Submission(s)...
1198 0