Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C
给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0。有一个操作是每个相邻的bank之间可以转钱,让你用最少的操作使每个bank的值为0。
一开始没什么思路,看了一下别人的题解,果然还是还是native...
要是让操作次数变少,首先划分和为0的区间个数要尽量多,比如一个区间的长度为k,那么他操作次数为k - 1,所以总的操作次数就是(n - 区间的个数)。
那么要算出区间的个数的话,那就要先算前缀和,比如前缀和sum[r] = x ,sum[l] = x其中(r > l),那么(l , r]之间的和为0。所以我们从1到n遍历一下前缀和,计算其中前缀和相同且次数出现最多的个数就行了。
#include <bits/stdc++.h>
using namespace std;
typedef __int64 LL;
map <LL , int> mp;
int main()
{
int n , res = ;
LL sum = , num;
scanf("%d" , &n);
for(int i = ; i < n ; ++i) {
scanf("%I64d" , &num);
sum += num;
mp[sum]++;
res = max(res , mp[sum]);
}
printf("%d\n" , n - res);
}
Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)的更多相关文章
- Codeforces Round #353 (Div. 2) C. Money Transfers 数学
C. Money Transfers 题目连接: http://www.codeforces.com/contest/675/problem/C Description There are n ban ...
- Codeforces Round #353 (Div. 2) C Money Transfers
题目链接: http://www.codeforces.com/contest/675/problem/C 题意: 给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动, ...
- Codeforces Round #353 (Div. 2) B. Restoring Painting 水题
B. Restoring Painting 题目连接: http://www.codeforces.com/contest/675/problem/B Description Vasya works ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #380 (Div. 2)/729D Sea Battle 思维题
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #575 (Div. 3) 昨天的div3 补题
Codeforces Round #575 (Div. 3) 这个div3打的太差了,心态都崩了. B. Odd Sum Segments B 题我就想了很久,这个题目我是找的奇数的个数,因为奇数想分 ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
随机推荐
- 使用netcat进行反弹链接的shellcode
from:http://morgawr.github.io/hacking/2014/03/29/shellcode-to-reverse-bind-with-netcat/ 这篇文章主要是谈,在远程 ...
- Effective C++学习笔记 条款07:为多态基类声明virtual析构函数
一.C++明确指出:当derived class对象经由一个base class指针被删除,而该base class带着一个non-virtual析构函数,其结果未定义——实际执行时通常发生的是对象的 ...
- Oracle的rownum原理和使用(整理几个达人的帖子)
整理和学习了一下网上高手关于rownum的帖子: 参考资料: http://tech.ddvip.com/2008-10/122490439383296.html 和 http://tenn.jav ...
- HDU 4870 Rating (2014 Multi-University Training Contest 1)
Rating Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- BZOJ_1052_[HAOI2007]_覆盖问题_(二分+贪心)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1052 网格图,给出\(n\)个点,要求用3个边长相同的正方形覆盖所有点,求最小边长. 分析 显 ...
- 安卓表格布局android:collapseColumns,android:shrinkColumns和stretchColumn
TableLayout的行数由开发人员直接指定,即有多少个TableRow对象(或View控件),就有多少行. TableLayout的列数等于含有最多子控件的TableRow的列数.如第一Table ...
- 自定义View等待旋转
效果图 1 string.xml <string name="default_progressbar">Default Progressbar:</string& ...
- AspNet WebApi OData 学习
OData介绍:是一个查询和更新数据的Web协议.OData应用了web技术如HTTP.Atom发布协议(AtomPub)和JSON等来提供对不同应用程序,服务 和存储的信息访问.除了提供一些基本的操 ...
- busybox filesystem ts_config: No such file or directory
/******************************************************************** * busybox filesystem ts_config ...
- 【Java学习笔记】函数使用
package aaa; public class aaa { public static int add(int a,int b) { return a+b; } public static voi ...