链接:

https://codeforces.com/contest/1180/problem/B

题意:

Nick had received an awesome array of integers a=[a1,a2,…,an] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a1⋅a2⋅…an of its elements seemed to him not large enough.

He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index i (1≤i≤n) and do ai:=−ai−1.

For example, he can change array [3,−1,−4,1] to an array [−4,−1,3,1] after applying this operation to elements with indices i=1 and i=3.

Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.

Help Kolya and print the array with the maximal possible product of elements a1⋅a2⋅…an which can be received using only this operation in some order.

If there are multiple answers, print any of them.

思路:

先将所有正值变成负数,偶数不处理,奇数吧最小的变成正数。

代码:

#include<bits/stdc++.h>
using namespace std; const int MAXN = 1e5+10;
int a[MAXN]; int main()
{
int n, m, x;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> a[i];
if (a[i] >= 0)
a[i] = -a[i]-1;
if (a[i] < m)
{
m = a[i];
x = i;
}
}
if (n%2 == 1)
a[x] = -a[x]-1;
for (int i = 1;i <= n;i++)
cout << a[i] << ' ' ;
cout << endl; return 0;
}

Codeforces Round #569 (Div. 2) B. Nick and Array的更多相关文章

  1. Codeforces Round #569 (Div. 2) 题解A - Alex and a Rhombus+B - Nick and Array+C - Valeriy and Dequ+D - Tolik and His Uncle

    A. Alex and a Rhombus time limit per test1 second memory limit per test256 megabytes inputstandard i ...

  2. Codeforces Round #569 (Div. 2)A. Alex and a Rhombus

    A. Alex and a Rhombus 题目链接:http://codeforces.com/contest/1180/problem/A 题目: While playing with geome ...

  3. Codeforces Round #569 (Div. 2) C. Valeriy and Deque

    链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...

  4. Codeforces Round #569 Div. 1

    A:n-1次操作后最大值会被放到第一个,于是暴力模拟前n-1次,之后显然是循环的. #include<bits/stdc++.h> using namespace std; #define ...

  5. Codeforces Round #179 (Div. 1) A. Greg and Array 离线区间修改

    A. Greg and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/295/pro ...

  6. Codeforces Round #331 (Div. 2) B. Wilbur and Array 水题

    B. Wilbur and Array Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/596/p ...

  7. Codeforces Round #258 (Div. 2) B. Sort the Array

    题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...

  8. Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)

    http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...

  9. Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心

    D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...

随机推荐

  1. 【Ruby on Rails 学习六】Ruby 类 的入门

    1.什么是类 2.类与实例的区别 3.自定义简单的类 生活中的垃圾分类,是集合上的概念 比如数学上的   1  a  2  b  c  4  5分类为数字1 2 4 5 ,字母  a  b  c ir ...

  2. 《Python编程从0到1》笔记4——你分得清“索引和切片”吗?

    Python为序列类型(sequence types)[1]提供了独特的索引(indexing)和切片(slicing)机制以访问序列的某个元素或某一部分. [1] 如list, tuple, ran ...

  3. 【Qt开发】布局控件之间的间距设置

    void QLayout::setContentsMargins ( int left, int top, int right, int bottom ) Sets the left, top, ri ...

  4. CSS:文字水平居中的写法

    <view class='kk'> 水平垂直居中文字 </view> .kk{ border: 1px solid #000000; width: 200px; height: ...

  5. Oracle恢复ORA-00600: 内部错误代码, 参数: [kcratr_scan_lastbwr] 问题的简单解决

    Oracle恢复ORA-00600: 内部错误代码, 参数: [kcratr_scan_lastbwr] 1. 简单处理 sqlplus / as sysdba startup mount recov ...

  6. [转帖]linux进程管理总结

    linux进程管理总结 https://www.cnblogs.com/chenfangzhi/p/10660355.html 高手总结的.. 看出来我是菜逼. 目录 一.进程相关的概念 二.关闭会话 ...

  7. spring aop之父子容器

    需求;项目对外提供接口,要求每个对外接口都要进行token认证. 解决办法:写一个token认证的工具类,在每个需要认证的接口方法开始的地方,调用工具类中的token认证方法. 问题:因为要满足指定条 ...

  8. GPIB、USB、PCI、PCI Express和以太网/LAN/LXI

    GPIB 我们研究的第一个总线是IEEE 488总线,较为熟悉的称谓是GPIB(通用接口总线).GPIB是一种在业界已经得到证明的专为仪器控制应用设计的总线.GPIB在过去30年来一直是鲁棒的.可靠的 ...

  9. HDU 1159 Common Subsequence 最长公共子序列

    HDU 1159 Common Subsequence 最长公共子序列 题意 给你两个字符串,求出这两个字符串的最长公共子序列,这里的子序列不一定是连续的,只要满足前后关系就可以. 解题思路 这个当然 ...

  10. eclipse project--->clean作用

    eclipse project-->clean  ,clean主要是class文件删除,并同时编译新的工程,生成新的class文件. 如果修改代码后,在运行时,还是旧代码,可能class文件还是 ...