Codeforces Round #353 (Div. 2) C Money Transfers
题目链接:
http://www.codeforces.com/contest/675/problem/C
题意:
给一个数组,每个数与他相邻的数相连,第一个与最后一个相连,每个数的数值可以左右移动,问最少的移动次数使所有的数都为零。
题解:
把数组分成若干个部分,每个部分和都为0,每部分最多移动len-1,这样分的越多,得到的结果就越优。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std; const int maxn=;
typedef __int64 LL; int n;
LL sum[maxn];
int arr[maxn];
map<LL,int> mp; void init(){
mp.clear();
} int main(){
while(scanf("%d",&n)==&&n){
init();
for(int i=;i<=n;i++){
scanf("%d",arr+i);
}
sum[]=arr[];
mp[sum[]]++;
int ma=;
for(int i=;i<=n;i++){
sum[i]=sum[i-]+arr[i];
mp[sum[i]]++;
if(mp[sum[i]]>ma) ma=mp[sum[i]];
}
int ans=n-ma;
printf("%d\n",ans);
}
return ;
}
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://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- Codeforces Round #353 (Div. 2) ABCDE 题解 python
Problems # Name A Infinite Sequence standard input/output 1 s, 256 MB x3509 B Restoring P ...
- Codeforces Round #353 (Div. 2)
数学 A - Infinite Sequence 等差数列,公差是0的时候特判 #include <bits/stdc++.h> typedef long long ll; const i ...
- Codeforces Round #353 (Div. 2) E. Trains and Statistic 线段树+dp
题目链接: http://www.codeforces.com/contest/675/problem/E 题意: 对于第i个站,它与i+1到a[i]的站有路相连,先在求所有站点i到站点j的最短距离之 ...
- Codeforces Round #353 (Div. 2) D. Tree Construction 二叉搜索树
题目链接: http://codeforces.com/contest/675/problem/D 题意: 给你一系列点,叫你构造二叉搜索树,并且按输入顺序输出除根节点以外的所有节点的父亲. 题解: ...
- Codeforces Round #353 (Div. 2) D. Tree Construction (二分,stl_set)
题目链接:http://codeforces.com/problemset/problem/675/D 给你一个如题的二叉树,让你求出每个节点的父节点是多少. 用set来存储每个数,遍历到a[i]的时 ...
- 线段树+dp+贪心 Codeforces Round #353 (Div. 2) E
http://codeforces.com/contest/675/problem/E 题目大意:有n个车站,每个车站只能买一张票,这张票能从i+1到a[i].定义p[i][j]为从i到j所需要买的最 ...
- Codeforces Round #353 (Div. 2) E. Trains and Statistic dp 贪心
E. Trains and Statistic 题目连接: http://www.codeforces.com/contest/675/problem/E Description Vasya comm ...
随机推荐
- POJ C++程序设计 编程作业—类和对象 编程题#1
编程题#1 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 下面程序输出的结 ...
- C# 中解决页面刷新后字体等变大问题
来源:http://blog.csdn.net/wcsjsdn/article/details/5109605 我们在.net开发中时常会遇到一个问题,那就是,当点击某个按钮后,调用js语句,当点击& ...
- SQL如何查询对应的object
SQL如何查询对应的Object 编写人:CC阿爸 2014-6-17 在日常SQL数据库的操作中,常常需要查询那些对象,如那些sp会包括对该表的操作,那些job会对应执行该sp等相关内容.总之是 ...
- c#获取多个List<class>合并、并将相同条件下的值累计sum
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 网页热力图 heatmap js
HBuilder +js 实现网页热力图 废话不多说,上代码 <!DOCTYPE html> <html> <head> <title>111</ ...
- (转)Arcgis API常用接口调用方法
var map, navToolbar, editToolbar, tileLayer, toolbar;//var mapBaseUrl = "http://localhost:8399/ ...
- CSS3常用功能的写法
随着浏览器的升级,CSS3已经可以投入实际应用了. 但是,不同的浏览器有不同的CSS3实现,兼容性是一个大问题.上周的YDN介绍了CSS3 Please网站,该网站总结了一些常用功能的写法. 以下就是 ...
- FireFox Prevent this page from creating addtional dialogs 火狐浏览器 设置 阻止此页面创建更多对话框
FireFox英文版本老弹出“Prevent this page from creating addtional dialogs”的确认框 FireFox english version alert ...
- python自学笔记一
之前看过一段时间的小甲鱼零基础自学python,b站上有高清免费资源[av4050443],但是作为零基础实在学得艰难,下载了python核心编程pdf,在这里做一些笔记. 虽然使用的是第二版的教材, ...
- python 常用函数、内置函数清单
文章内容摘自:http://www.cnblogs.com/vamei 1.type() 查询变量的类型 例: >>> a = 10>>> print a10> ...