Codeforces Round #353 (Div. 2) C. Money transfers (thinking)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.