Codeforces round #353div2 C
题目来源: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的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #370 - #379 (Div. 2)
题意: 思路: Codeforces Round #370(Solved: 4 out of 5) A - Memory and Crow 题意:有一个序列,然后对每一个进行ai = bi - bi ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
随机推荐
- DSP TMS320C6000基础学习(3)——CCS v5软件开发环境搭建
================================================== DSP CCS工程文件构成 =================================== ...
- sql语句各种九九乘法表
下面用while 和 if 条件写的SQL语句的四种九九乘法表 --9x9 左下角 ) BEGIN SET @S='' WHILE @J<=@I BEGIN )))))) END PRINT @ ...
- mysql用户修改密码
1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 2:用mysq ...
- for_each 用法!
class MapTest:public CapTest{ private: set <string> MyTestContain; typedef pair <string,int ...
- word2vec的艰难成长史
1.首先在网站上面下载gensim,我是在11服务器上面下载的 2.使用winpython打开 3.在command windows 下使用pip install gensim这句话进行,原先使用这句 ...
- Linux & Python 导航目录
< Python学习手册(第4版)>< Python Cookbook(第2版)>中文版.pdf< Python 高级编程>< Python 基础教程 第二版 ...
- baike并行计算概念
并行计算 概论 ▪ 高性能计算 ▪ 计算机集群 ▪ 分布式计算 ▪ 网格计算 ▪ 云端运算 方式 ▪ Bit-level parallelism ▪ Instruction level ...
- 传智播客8月C/C++基础班开班
秋天已经向我们走来,在这个充满收获的季节里,大家齐聚传智C/C++学院这个大家庭,无论你曾经从事什么工作,都拥有着一颗热爱C/C++的心,为了自己心中的梦想,大家要付出百倍的努力,要做到&quo ...
- allVncClients
VNC Viewer Free Edition 37 RealVNC Ltd. 15,367 Freeware 1021.58 KB VNC is client and server remo ...
- 第35讲 Activity入门和跳转
第35讲Activity入门和跳转 1.Activity Activity是用户接口程序.在Android当中,Activity提供可视化的用户界面,一个Android应用通常由多个activity组 ...