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的更多相关文章

  1. Codeforces Round #182 (Div. 1 + Div. 2)

    A. Eugeny and Array \(r-l+1\)是奇数时,和显然无法为0. 奇数的情况需要判断-1和1的个数是否大于等于长度的一半. B. Eugeny and Play List 模拟. ...

  2. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  3. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  4. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  5. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  6. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  7. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  8. [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 ...

  9. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

随机推荐

  1. linux调度器系列

    http://blog.csdn.net/wudongxu/article/category/791519

  2. iscsi介绍及iscsi target配置

    iSCSI 主要是透过 TCP/IP 的技术,将储存设备端透过 iSCSI target (iSCSI 目标) 功能,做成可以提供磁盘的服务器端,再透过 iSCSI initiator (iSCSI ...

  3. 详解SSH框架的原理和优点

    Struts的原理和优点.        Struts工作原理  MVC即Model-View-Controller的缩写,是一种常用的设计模式.MVC 减弱了业务逻辑接口和数据接口之间的耦合,以及让 ...

  4. CentOS 6.7编译安装MySQL 5.6

    1.安装前准备 yum install make gcc gcc-c++ ncurses-devel perl bison-devel yum groupinstall "Developme ...

  5. asp.net 的脚本

    asp.net的 Web 控件有时会包装一些用户端脚本 (client-side scripting),在控件被绘制时输出到用户端,这些脚本多数被包装在 DLL 的资源档中,并由 ScriptReso ...

  6. python 学习笔记(一)

    在Windows上安装Python 首先,从Python的官方网站www.python.org下载最新的2.7.9版本,地址是这个: http://www.python.org/ftp/python/ ...

  7. 绝对炫的幻灯片插件-SKITTER

    绝对炫的幻灯片插件-SKITTER 所属分类:媒体-幻灯片和轮播图,图片展示,滑块和旋转 Includes code source // Styles <link href="css/ ...

  8. js获取上一个月、下一个月

    /** * 获取上一个月 * * @date 格式为yyyy-mm-dd的日期,如:2014-01-25 */ function getPreMonth(date) { var arr = date. ...

  9. Android 使用弹出对话框,报Unable to add window错误

    今天在使用Android弹出对话框的时候,报了一个unable to add window错误,我的代码如下 new AlertDialog.Builder(getApplicationContext ...

  10. 【转载】一步一步搭建自己的iOS网络请求库

    一步一步搭建自己的iOS网络请求库(一) 大家好,我是LastDay,很久没有写博客了,这周会分享一个的HTTP请求库的编写经验. 简单的介绍 介绍一下,NSURLSession是iOS7中新的网络接 ...