码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 367B

时间:2014-08-27 14:41:57      阅读:199      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   ar   div   代码   

题目代码到是不难但是很难想通题目的解决方法。

#include<iostream>
using namespace std;
int person[110];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        memset(person,0,sizeof(person));
        int a,b,c;
        for(int i=0;i<m;i++)
        {
            cin>>a>>b>>c;
            person[a]-=c;
            person[b]+=c;
        }
        int ret = 0;
        for(int i=1;i<=n;i++)
        {
            if(person[i]>=0)
                ret+=person[i];
        }
        cout<<ret<<endl;
    }
    
    return 0;
}

这就是A 欠 B 5,则arr[A]-=5;arr[b]+=5;最后把整数加起来就可以了。

codeforces 367B

标签:style   blog   color   os   io   for   ar   div   代码   

原文地址:http://www.cnblogs.com/chaiwentao/p/3939356.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!