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 ...
随机推荐
- Clearing Search Values
Use the SearchClear() method which is part of the Field class to clear search values on a particul ...
- JQuery.tmpl()的用法
动态请求数据来更新页面是现在非常常用的方法,现在通过Ajax请求返回的数据更多的是json对象, 为了解决js动态拼接数据这方面的问题,JavaScript 也可以利用模版来解决这些问题,比如基于 j ...
- zend studio导入thinkphp的乱码问题
刚刚导入thinkphp有乱码还有错误怎么办? windows -> preference -> Work space -> text file encodeing设置为 UTF-8 ...
- SQL Server 基础:拾遗
1.一条完整的sql语句: select top | distinct 字段, 表达式, 函数, ... from 表表达式 where 筛选条件 group by 分组条件 having 筛选条件 ...
- SQL Server 基础:Join用法
Join(麻蛋 废话不多说 有图有真相) 测试数据脚本 CREATE TABLE Atable ( S# INT, Sname ), Sage INT, Sfrom ) ) insert into ...
- [转]判断程序是否运行在 Windows x64 系统下
以下功能代码判断是否运行在 Windows x64 下.本例使用 Windows API 函数 IsWow64Process,具体请参考MSDN文档:http://msdn.microsoft.com ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- hdu 3530 Subsequence
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3530 Subsequence Description There is a sequence of i ...
- 微软开放技术(中国)携 CKAN 和 OData 技术引入基于 Azure 的开放数据平台
今天,微软开放技术(中国)通过微软公有云Azure引入一个全新的开放数据平台,该平台基于开源数据门户解决方案 CKAN,以及由微软开放技术(中国)特别针对中国市场优化的ODATA插件来增强其国际化和本 ...
- 使用IC框架开发跨平台App的备忘录123
1,关于图标与启动屏幕 icon.png 192x192splash.png 2208x2208 将这两个图片放在resources目录下,在终端执行:ionic resources --iocn - ...