Codeforces Round #569 (Div. 2) B. Nick and Array
链接:
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的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #569 (Div. 2) C. Valeriy and Deque
链接: https://codeforces.com/contest/1180/problem/C 题意: Recently, on the course of algorithms and data ...
- Codeforces Round #569 Div. 1
A:n-1次操作后最大值会被放到第一个,于是暴力模拟前n-1次,之后显然是循环的. #include<bits/stdc++.h> using namespace std; #define ...
- 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 ...
- 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 ...
- Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接:http://codeforces.com/contest/451/problem/B 思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把 ...
- Codeforces Round #510 (Div. 2) D. Petya and Array(离散化+反向树状数组)
http://codeforces.com/contest/1042/problem/D 题意 给一个数组n个元素,求有多少个连续的子序列的和<t (1<=n<=200000,abs ...
- 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.配置详解: 使用app.json文件来对微信小程序进行全局配置,决定页面文件的路径.窗口表现.设置网络超时时间.设置多 tab 等. 1>pages 接受一个数组,每一项都是字符串,来指定小 ...
- UML_2_浅谈UML的概念和模型之UML九种图
转载:https://my.oschina.net/zhumenzhongren/blog/667353 上文我们介绍了,UML的视图,在每一种视图中都包含一个或多种图.本文我们重点讲解UML每种图的 ...
- javase程序设计上机作业1
package javaxgp.teacher.test; import java.math.BigInteger; import java.util.Scanner; import java.uti ...
- 修改了Mysql密码后连接不到服务且无报错信息解决方法以及修改密码方法
安装MYSQL后更改了root的密码后用 net start mysql 启动时出现:无法启动,无报错信息 使用以下命令:1.管理员方式cmd进入mysql安装目录的bin目录下2.执行命令:mysq ...
- Websocket --(2)实现
首先声明,本篇博文参考文章 https://blog.csdn.net/jack_eusong/article/details/79064081 主要在于理解和自己动手搭建环境,自己搭建的过程中会发生 ...
- SCP,scp linux2台机器之间如何传输文件
关键词:scp 转自: http://blog.csdn.net/gatieme https://blog.csdn.net/gatieme/article/details/51673229 scp传 ...
- [转帖]oracle 00600 4194 4193 问题的处理
oracle断电重启之ORA-00600[4194] https://www.cnblogs.com/xwdreamer/p/3778383.html 部门的机器出现异常 断电导致的 错误 从网上学了 ...
- WordPress 在Ubuntu下安装插件、主题输入FTP后无法创建目录
最近自己在搞基于lnmp+wordpress的个人博客, 一切都就绪后,想改变下自己的主题,然后去Wordpress里面内置的主题安装下载的时候,提示:无法创建目录! 一般我们在Ubuntu系统上面安 ...
- Java作业 题目:16版.真实员工数统计
题目:16版.真实员工数统计 该资源支持按部自动给分,评分规则如下: sjkdfhslkfdhdsiog函数定义测试 sjkdfhslkfdhdsiog函数定义测试 sjkdfhslkfdhdsiog ...
- Maven build 命令介绍(转)
常用命令: 打包:mvn package编译:mvn compile清空:mvn clean(清除编译后目录,默认是target目录)运行测试:mvn test安装jar包到本地仓库中:mvn ins ...