Yaroslav and Sequence
Codeforces Round #182 (Div. 1) A:http://codeforces.com/contest/301/problem/A
题意:给你2*n-1个数,你每次可以选择n个连续的数,把这个n个数*-1,问你进行若干次操作,这2*n-1个数之和最大是多少。
题解:结论很简单:当n是奇数的时候,那么你一次操作可以增加或者减少一个负数,所以这时候所有的负数都能变成整数。当n是偶数的时候,那么你一次操作可以增加或者减少2个负数,如果负数的个数是偶数,那么所有的负数都可以变成整数,否则,就会还剩下一个负数,显然这个负数必须是绝对值最小的那个数。所以,结果出来啦。
思维过程;一开始也分n奇数偶数讨论,但是始终不知从哪里下手,没有进行深入分析,所以没有得到答案。最后还是问了别人,这样的思维还是不习惯。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
int ans1,ans2,sum,temp;
int a1,n;
int main(){
while(~scanf("%d",&n)){
int ans1=ans2=,sum=a1=;
for(int i=;i<=*n-;i++){
scanf("%d",&temp);
if(temp>){
sum+=temp;
ans1=min(ans1,temp);
}
else {
sum+=abs(temp);
ans2=min(ans2,-temp);
a1++;
}
}
if(n&)printf("%d\n",sum);
else if(a1&){
printf("%d\n",sum-*min(ans1,ans2));
}
else {
printf("%d\n",sum);
}
}
}
Yaroslav and Sequence的更多相关文章
- Codeforces Round #182 (Div. 1 + Div. 2)
A. Eugeny and Array \(r-l+1\)是奇数时,和显然无法为0. 奇数的情况需要判断-1和1的个数是否大于等于长度的一半. B. Eugeny and Play List 模拟. ...
- oracle SEQUENCE 创建, 修改,删除
oracle创建序列化: CREATE SEQUENCE seq_itv_collection INCREMENT BY 1 -- 每次加几个 STA ...
- Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等
功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...
- DG gap sequence修复一例
环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...
- Permutation Sequence
The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列
Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
随机推荐
- 【android】ImageView的src和background的区别以及两者的妙用
一.ImageView中XML属性src和background的区别: background会根据ImageView组件给定的长宽进行拉伸,而src就存放的是原图的大小,不会进行拉伸 .src是图片内 ...
- docker 实战---部署tomcat\weblogic集群 (二)
安装tomcat镜像 准备好须要的jdk tomcat等软件放到home文件夹以下 启动一个虚拟机 docker run -t -i -v /home:/opt/data --name mk_tom ...
- NSNotificationCenter消息机制的介绍
转载自http://www.cnblogs.com/pengyingh/articles/2367374.html NSNotificationCenter的作用是专门提供程序中不同类之间的消息通讯而 ...
- 【Android】android镜像翻转
Android镜像翻转指的是将屏幕进行水平的翻转,达到所有内容显示都会反向的效果,就像是在镜子中看到的界面一样.这种应用的使用场景相对比较受限,主要用在一些需要使用Android手机界面进行镜面投影的 ...
- CSS定位:相对定位、绝对定位和固定定位(relative absolute fixed)
相对定位:position:relative; 不脱离文档流,参考自身静态位置通过top,bottom,left,right定位,并且可通过z-index进行层次分级. 绝对定位:position:a ...
- jquery选择器取值和url正则匹配
用到的简单jquery知识,简单总结一下,一是能加深自己的记忆,二是方便自己以后查看.常言道"好记性不如烂笔头",要养成常总结.常记录的好习惯.慢慢的发现jquery很有意思,很强 ...
- Html网页生成Pdf
在http://code.google.com/p/wkhtmltopdf/downloads/list下载安装程序. 1.添加引用 using System.Diagnostics; 添加引用 2. ...
- 在eclipse中将java导出为可执行文件.
Ref: http://java.chinaitlab.com/Eclipse/812775.html and http://www.javavids.com/video/how-to-create- ...
- linq学习笔记:将List<T> 转换为 Dictionary<T Key,T Value>
运用Linq,将List<T> 转换为 Dictionary<T Key,T Value> 即:List<T> ToDictionary<T Key,T V ...
- CentOS7下配置Openvpn 2.3.12
1.下载安装包 #wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.09.tar.gz#wget http://swupdate. ...