题解:
考虑一个连续的段,长度为l,如果该段的区间和为0的话,那么就操作l-1次就够了
现在有n个数,你分成了k段,那么你就需要操作n-k次
那么只要k最大就好了
然后暴力枚举前缀和相等的,取最大就好了
Description
Input
Output
Sample Input 1
3
3
5 0 -5
4
-1 0 1 0
4
1 2 3 -6
Sample Output 1
1
2
3
Hint
出自:codeforces Round #353(Div.2) C Money Transfers
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
map<ll,int>ma;
int main()
{
int t,n;
ll a;
scanf("%d",&t);
while(t--)
{
ll sum=0;
int ans=0;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld",&a);
sum+=a;
ma[sum]++;
ans=max(ans,ma[sum]);
}
printf("%d\n",n-ans);
ma.clear();
}
return 0;
}