The original question, please poke here
Test instructions
N banks are arranged in a roundabout form. Each bank has a certain balance of AI, each time can be transferred between any adjacent banks. Ask
At least how many transfers are required so that all banks have a balance of 0.
Analysis:
As the total balance of all banks is 0, if the whole ring is regarded as a paragraph, it needs n-1 to make all balances 0.
The AI is divided into K-sum=0 parts, each part of the length of Li, so that every part of all banks clear 0 need li-1 step. N A
Bank clearance 0 requires a total of n-k steps.
So that is to ask (n-k) min, then the greater the value of k, the better.
Consider the prefix and, if SUM[I]==SUM[J], the interval [i+1,j] must be 0, and the sum of [j+1,n] and [1,i] intervals is also 0.
Find the prefix and the maximum number of occurrences, that is, the maximum number of fragments that can be divided into 0.
1#include <bits/stdc++.h>2 3 using namespacestd;4 5typedefLong Longll;6 7ll a[100005];8Map<ll,int>MP;9 Ten intMain () One { A intN; - while(~SCANF ("%d",&N)) - { the mp.clear (); -ll sum =0; - intAns = n1; - for(intI=0; i<n;i++) + { -scanf"%i64d",&a[i]); +Sum + =A[i]; Amp[sum]++; atans = min (ans,n-mp[sum]); - } -printf"%d\n", ans); - } - return 0; -}
Codeforces Round #353 (Div. 2) C. Money transfers (thinking)