codeforces 675C Money Transfers map

上面是官方题解,写的很好,然后就A了,就是找到前缀和相等的最多区间,这样就可以减去更多的1
然后肯定很多人肯定很奇怪为什么从1开始数,其实从2开始也一样,因为是个环,从哪里开始记录前缀和都一样
我们的目的是为了找到更多的区间和为0,从哪开始都一样,只是一个标准罢了
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <queue>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int N=1e3+;
map<LL,int>mp;
int main(){
int n;
scanf("%d",&n);
int ans=n-;
LL sum=;
for(int i=;i<n;++i){
int t;
scanf("%d",&t);
sum+=t;
++mp[sum];
ans=min(ans,n-mp[sum]);
}
printf("%d\n",ans);
return ;
}
codeforces 675C Money Transfers map的更多相关文章
- Codeforces 675C Money Transfers 思维题
原题:http://codeforces.com/contest/675/problem/C 让我们用数组a保存每个银行的余额,因为所有余额的和加起来一定为0,所以我们能把整个数组a划分为几个区间,每 ...
- CodeForces 675C Money Transfers(贪心+奥义维护)
题意:n个银行. 其中存款有+有-. 总和为0. n个银行两两相邻((1,n),(1,2)...(n-1,n)); 问最少移动几次(只能相邻移动)能把所有数变为0. 分析:思路很简单,起始答案算它为n ...
- codeforces 675C C. Money Transfers(贪心)
题目链接: C. Money Transfers time limit per test 1 second memory limit per test 256 megabytes input stan ...
- Codeforces 977F - Consecutive Subsequence - [map优化DP]
题目链接:http://codeforces.com/problemset/problem/977/F 题意: 给定一个长度为 $n$ 的整数序列 $a[1 \sim n]$,要求你找到一个它最长的一 ...
- CodeForces 567C. Geometric Progression(map 数学啊)
题目链接:http://codeforces.com/problemset/problem/567/C C. Geometric Progression time limit per test 1 s ...
- Codeforces 567C - Geometric Progression - [map维护]
题目链接:https://codeforces.com/problemset/problem/567/C 题意: 给出长度为 $n$ 的序列 $a[1:n]$,给出公比 $k$,要求你个给出该序列中, ...
- CodeForces - 583C GCD Table map的auto遍历 ,有点贪心的想法
题意:给你n*n gcd表中的所有数(以任意顺序) ,求对角线上的n个数分别是什么.gcd表定义如下,先将n个数填在对角线的上,然后将各个格子填上对应对角线上的数的gcd值,也就是V[i][j]=gc ...
- codeforces 589A Email Aliases(map)
Description Polycarp has quite recently learned about email aliases. Of course, he used to suspect t ...
- Codeforces510 D. Fox And Jumping
Codeforces题号:#510D 出处: Codeforces 主要算法:map+DP 难度:4.6 思路分析: 题意:给出n张卡片,分别有l[i]和c[i].在一条无限长的纸带上,你可以选择花c ...
随机推荐
- 简单易懂的现代魔法——Play Framework攻略3
接前文:http://www.cnblogs.com/Kassadin/p/4343682.html 目前为止,我们已经研究了Play Framework的体系结构以及Web应用程序的工作原理.本来今 ...
- python之self (转)
首先明确的是self只有在类的方法中才会有,独立的函数或方法是不必带有self的.self在定义类的方法时是必须有的,虽然在调用时不必传入相应的参数. self名称不是必须的,在python中self ...
- http://www.cnblogs.com/xia520pi/archive/2012/05/16/2504205.html
http://www.cnblogs.com/xia520pi/archive/2012/05/16/2504205.html http://www.cnblogs.com/madyina/p/370 ...
- 排序 归并排序&逆序对
void MergeArray(int cry[],int temp[],int begin,int middle,int end) { int i=begin; int j=middle+1; in ...
- Unrecognized selector sent to instance xxxxxxx
两个界面传递参数时报这个错误,经检查发现,是因为目标视图没有关联对应的controller.
- struts2中token防止重复提交表单
struts2中token防止重复提交表单 >>>>>>>>>>>>>>>>>>>&g ...
- 【C#设计模式——创建型模式】简单工场模式
进入码农行列也有一年半载了,仍然感觉自己混混沌沌,无所事事,无所作为,,,想想都下气,下气归下气,仍要奋起潜行,像愤怒的小鸟一边又一遍的冲向猪头也好,像蜗牛一样往前蹭也罢,总之要有蚂蚁啃骨头的精神!! ...
- ASP.NET 数据绑定常用代码及其性能分析
用DataBinder.eval 绑定不必关心数据来源(Dataread或dataset).不必关心数据的类型eval会把这个数据对象转换为一个字符串.在底层绑定做了很多工作,使用了反射性能.正因为使 ...
- Building Xcode iOS projects and creating *.ipa file from the command line
For our development process of iOS applications, we are using Jenkins set up on the Mac Mini Server, ...
- .net项目的svn Global ignore pattern
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__ *.rej *~ #*# .#* .*.swp .DS_S ...