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. 小白学phoneGap《构建跨平台APP:phoneGap移动应用实战》连载四(使用程序载入事件)

    在了解了PhoneGap中都有哪些事件之后,本节将開始对这些事件的使用方法进行具体地介绍.本节要介绍的是程序载入事件,也就是deviceready.pause和resume这3个事件. [范例4-2 ...

  2. CSU1312:榜单(模拟)

    Description ZZY很喜欢流行音乐,每周都要跟踪世界各地各种榜单,例如Oricon和Billboard,现在给出每周各个单曲的销量请给出每周的TOP5以及TOP5中各个单曲的浮动情况. 量的 ...

  3. [PWA] 19. Cache the avatars

    Cache the avatars is little different from cache photos. We need to serve the page with our cache da ...

  4. android 55

    智能家居:可以联网可以用指令操作可以返回状态.智能微波炉智能眼镜智能手表. Android作者Andy Rubin,2007年正式由谷歌推广,开源的. 安卓体系结构和开发一个闹钟的调用结构图: 安卓和 ...

  5. MySQL的优化点总结---通过计算多种状态的百分比看MySQL的性能情况

    1 读写比例: show global status like 'com_select';  获得服务器启动到目前查询操作执行的次数:show global status like 'com_inse ...

  6. Redhat 官方Performance_Tuning_Guide

    https://access.redhat.com/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html/Performance_Tuning_Gui ...

  7. httpd cgi程序配制+.py .cgi执行

     vi /etc/httpd/conf/httpd.conf httpd默认首页配制: DirectoryIndex index.html index.html.var 首页的位置定义: Docume ...

  8. eclipse 常见问题及解决

    1. Target runtime Apache Tomcat v6.0 is not defined.错误解决方法 原文:http://blog.csdn.net/xw13106209/articl ...

  9. java中的mmap实现--转

    什么是mmap mmap对于c程序员很熟悉,对于java程序员有点陌生.简而言之,将文件直接映射到用户态的内存地址,这样对文件的操作不再是write/read,而是直接对内存地址的操作. 在c中提供了 ...

  10. ES6的let命令实现猜想

    今天看了看阮一峰的<ECMAScript 6入门>的let和const命令,看完let之后自己测试了一把,仿佛处在云里雾里之中.代码如下: "use strict"; ...