题目来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=117863#problem/C

题目大意:给你n个数字,代表这个人在n个银行里面的存款数目,这些银行围成一个环,银行里面的资金

可以流向他周围的银行,问你最少要流动多少次,才能使得所有银行里的存款都是0。

思路分析:要将环分割成多个和为0的分组分别处理,每一个和为0分组,操作次数是分组大小-1

如果最终分了k组,那么操作次数就是n-k,很显然k越大,操作次数越少,现在问题就变成了最多能

分成多少个和为0的分组,关于这个问题,可以用前缀和实现,和为0的区间的个数==前缀和相等的

个数,证明很容易。

代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
using namespace std;
const int maxn=100000+100;
int a[maxn];
map<long long,int> m;
int main()
{
    int n;
    __int64 sum;
    int ma=0;
      scanf("%d",&n);
        sum=0;
        int ans=n-1;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            sum+=a[i];
            m[sum]++;
            ma=max(ma,m[sum]);
            ans=min(ans,n-m[sum]);
        }
        printf("%d\n",ans);
}

Codeforces round #353div2 C的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #370 - #379 (Div. 2)

    题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi  ...

  9. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

随机推荐

  1. 从零开始制作Minecraft启动器(C++开源)

    从零开始制作Minecraft启动器(C++开源) 新手飙车了~~~,MC启动器源码大放送,随心所欲打造自己的专属MC启动器,这不是易语言,是C++...分析原理,关键源码都有详细的注释,代码编好就打 ...

  2. ImportError No module named memcache

    ImportError: No module named memcache 没有找到windows下的memcache,我们就用linux下的包来安装 先下载memcache linux下的安装包 f ...

  3. 011_hasCycle

    /* * Author :SJQ * * Time :2014-07-16-20.21 * */ #include <iostream> #include <cstdio> # ...

  4. JavaScript 高级程序设计 第5章引用类型 笔记

    第五章 引用类型 一.object类型 1.创建方法: 1.使用new 操作符创建 var person=new object() Person.name=”Nicholasa” Porson.age ...

  5. C# window 窗体 保持最前显示

    两句话搞定 [DllImport("user32.dll", CharSet = CharSet.Auto)]  private static extern int SetWind ...

  6. python登陆教务管理系统

    想试着模拟登陆一些网站,这次先拿学校的教务管理系统练练手,写一下登陆的流程. 1.我们登陆的url:http://222.195.8.201,但我们所填的密码不是提交到这个页面上去,检查一下页面代码 ...

  7. 如何看懂XDEBUG+WEBGRIND?(转)

    看到一个很有用的东东,收藏.. http://blog.csdn.net/yukon12345/article/details/11408617 ~~~~~~~~~~ 使用:              ...

  8. Smarty 保留变量

    {$smarty} 保留变量 可以通过PHP的保留变量 {$smarty}来访问一些环境变量. 下面是这些变量的列表: 页面请求变量 页面请求变量如$_GET, $_POST, $_COOKIE, $ ...

  9. BZOJ1628: [Usaco2007 Demo]City skyline

    1628: [Usaco2007 Demo]City skyline Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 256  Solved: 210[Su ...

  10. cf442B Andrey and Problem

    B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...