codeforce 675C Money Transfers (思维)

原题地址:http://codeforces.com/contest/675/problem/C

 

题意:

 

题解

一个长度为n的区间,如果区间和为0,那么只要n-1次transfer就可以使区间为0;

我们将整个环切分为p个区间,使得每个区间和均为0,那么只需要n-p次transfer。

 

#include<bits/stdc++.h>

#define clr(x,y) memset((x),(y),sizeof(x))

using namespace std;
typedef long long LL;

const int maxn=1e5;

map <LL,int> mp;
int A[maxn+5];

int main(void)
{
    #ifdef ex
    freopen ("../in.txt","r",stdin);
    //freopen ("../out.txt","w",stdout);
    #endif

    int n;
    scanf("%d",&n);

    LL sum=0;
    int ans=0;

    for (int i=1;i<=n;++i)
    {
        scanf("%d",&A[i]);
        sum+=A[i];
        ++mp[sum];
        ans=max(ans,mp[sum]);
    }

    printf("%d\n",n-ans);
}

 

posted on 2016-06-14 20:01  zhong_wang  阅读(138)  评论(0编辑  收藏  举报

导航