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 ...
随机推荐
- C#客户端填充外部IE浏览器中网页文本(input)且不提交
//引用COM组件//Microsoft HTML Object Library//Microsoft Internet Controls 记得改成x86 SHDocVw.ShellWindows ...
- elasticsearch-6.2.3单机搭建
1.这里说明下,elasticsearch为了保证安全性需要创建新的用户名,需要在新的用户名下运行,本人用的是elasticsearch-6.2.3,centos7.3 2.切换目录到:cd usr/ ...
- Express全系列教程之(十一):渲染ejs模板引擎
一.简介 相比于jade模板引擎,ejs对原HTML语言就未作出结构上的改变,只不过在其交互数据方面做出了些许修改,相比于jade更加简单易用.因此其学习成本是很低的.您也可参考ejs官网:https ...
- 【VS开发】使用WinPcap编程(2)——打开网络设备并且开始捕获数据包
这里需要特别强调的一个数据结构是pcap_t,它相当于一个文件描述符,代表一个已经打开的设备.我们对这个设备进行操作,就是对这个文件描述符进行操作. 首先是打开一个已知的设备,使用pcap_open( ...
- Android基础内容提供者ContentProvider的使用详解(转)
1.什么是ContentProvider 首先,ContentProvider(内容提供者)是android中的四大组件之一,但是在一般的开发中,可能使用的比较少. ContentProvider为不 ...
- python 生成器、三元表达式、列表推倒式、字典生成式、生成器表达式(总结)
1.生成器 def func(): yield g = func() next(g) x = yield 2.三元表达式 res = x if 条件 else y 3.列表推导式,字典生成式,生成器表 ...
- 第六次学习总结&&第四次实验总结
Java实验报告 班级 1班 学号 20188390 姓名 宋志豪 实验四 类的继承 1.实验目的 (1)掌握类的继承方法: (2)变量的继承和覆盖,方法的继承.重载和覆盖实现: 2.实验内容 实验代 ...
- 【转帖】docker 部署vsftpd服务
docker 部署vsftpd服务 https://blog.csdn.net/ctwy291314/article/details/82012860 转帖学习一下 docker部署vsftpd服务 ...
- java中易错点
1.A instanceof B{这是没有好好利用java多态的表现} java中的二元操作符,测试A对象是否是B类的实例: 返回值:boolean类型 2.“==”与 “equals”的区别: = ...
- MySQL -2- 体系结构-多实例模块
0.在已创建mysql,port=3306的数据库前提下 需要删除/etc/.my.cnf再做以下操作 cp /etc/my.cnf /etc/my.cnf.3306 1.mkdir -p /u02/ ...