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 ...
随机推荐
- Thread的第四天学习
线程通信 wait notify synchronized + 同对象 才可 互斥 锁不是放在线程上的,放在共享资源内部的. wait 线程等待 notify 线程唤醒
- Mac 如果一定要写个锁屏程序的话就这样
package test; import java.io.BufferedReader; import java.io.File; import java.io.IOException; import ...
- QAQ数论模板笔记√
#include <cstdio> using namespace std; long long gcd(long long a, long long b) { // (a, b) ret ...
- 不重启使XP环境变量生效
不重启使XP环境变量生效 http://www.pkghost.cn/wz/sort0185/8874.html 在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环 ...
- 函数执行到return就结束了
遇到return,函数就结束了,不会往下执行 测试: class User { String name; int age; boolean fun1(int i){ if(i==1){ return ...
- 255. Verify Preorder Sequence in Binary Search Tree
题目: Given an array of numbers, verify whether it is the correct preorder traversal sequence of a bin ...
- java对称加密报错:Input length must be multiple of 8 when decrypting with padded cipher
HTTP Status 500 - Request processing failed; nested exception is javax.crypto.IllegalBlockSizeExcept ...
- Maven基本操作命令
1.mvn package 此命令包含一系列过程:validate-->compile-->test-->package Maven根据pom文件里packaging的配置,决定是生 ...
- [Codeforces673B]Problems for Round(思路,规律)
题目链接:http://codeforces.com/contest/673/problem/B 现在有n个题和m个相似的关系,现在要把他们分到2组去. 要求: 1组的所有题比2组难 每个组都得至少有 ...
- iOS学习笔记:frame,bound,center, anchorPoint
frame: View在它的Super View坐标系里的坐标 bound: 用来定义View自身坐标系和边界的Rect,Rect的原点表示View自身坐标系的原点坐标.举个例子: 一般情况下boun ...