CF374 Maxim and Array
贪心
如果有0先变成非0
如果负数的个数 应该变为偶数
之后就是每次将绝对值最小的值加K
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
typedef long long ll;
int N,K,X;
ll A[MAXN];
int tag[MAXN];
struct Node{
ll x; int id;
Node(ll a=0, int b=0):x(a),id(b){}
bool operator <(const Node &T) const {
return x > T.x;
}
};
ll Abs(ll x) {
if(x < 0) x *= -1;
return x;
}
void doo(int id,ll num) {
if(A[id] > 0) A[id] += num;
else A[id] -= num;
}
priority_queue<Node> Q;
int main(){
while(~scanf("%d %d %d",&N,&K,&X)) {
memset(tag,0,sizeof(tag));
while(!Q.empty()) Q.pop();
// int c1 = 0; int c2 = 0;
int c3 = 0; // pos zero neg
for(int i = 1; i <= N; ++i) {
scanf("%lld",&A[i]);
Q.push(Node(Abs(A[i]), i));
}
for(int i = 1; i <= N; ++i) {
if(A[i] < 0) c3 ++;
}
while(K) {
ll x = Q.top().x; int id = Q.top().id;
Q.pop();
if(x == 0) {
if(~c3&1) {
A[id] = -X;
c3 ++;
}else {
A[id] = X;
}
}else if(~c3&1){
ll tt = (x+X)/X;
if(tt > K) {
doo(id, -1ll*K*X);
break;
}else {
doo(id,-1ll*tt*X); K -= tt; K++;
}
c3 ++;
}else {
doo(id,X);
}
// printf("%d %lld\n",id,A[id]);
Q.push(Node(Abs(A[id]),id)); K--;
}
for(int i = 1; i <= N; ++i) printf("%lld ",A[i]); printf("\n");
}
return 0;
}
CF374 Maxim and Array的更多相关文章
- Codeforces Round #374 (Div. 2) D. Maxim and Array 贪心
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array 线段树+贪心
D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array —— 贪心
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...
- Codeforces F. Maxim and Array(构造贪心)
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 【24.17%】【codeforces 721D】Maxim and Array
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- CodeForces - 721D Maxim and Array (贪心)
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea ...
- Codeforces Round #374 (Div. 2) D. Maxim and Array
传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非 ...
- CodeForces 721D Maxim and Array
贪心,优先队列. 先看一下输入的数组乘积是正的还是负的. ①如果是负的,也就是接下来的操作肯定是让正的加大,负的减小.每次寻找一个绝对值最小的数操作就可以了. ②如果是正的,也是考虑绝对值,先操作绝对 ...
- Maxim and Array CodeForces - 721D (贪心)
大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值 贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值 #include <io ...
随机推荐
- Maven pom.xml简单归结
Maven pom.xml文件解释 请确保有相关的maven知识,包括Maven安装.Maven settings.xml解读.本文对POM的一些属性作一些摘录,详细的配置可查看此篇转载文章" ...
- JMS基础篇
首先我们需要下载 ActiveMQ:http://activemq.apache.org/. 启动 ActiveMQ 服务:解包下载的 ActiveMQ >进去其bin 目录>双击 act ...
- FindBugs简单应用
FindBugs是一种java代码的静态分析工具,无需开发人员费劲就能找出代码中可能存在的缺陷.FindBugs 不注重样式或者格式,它试图只寻找缺陷或者潜在的性能问题. 第一步,http://sou ...
- [Sdoi2017]新生舞会 [01分数规划 二分图最大权匹配]
[Sdoi2017]新生舞会 题意:沙茶01分数规划 貌似\(*10^7\)变成整数更科学 #include <iostream> #include <cstdio> #inc ...
- 51Nod 欢乐手速场1 A Pinball[DP 线段树]
Pinball xfause (命题人) 基准时间限制:1 秒 空间限制:262144 KB 分值: 20 Pinball的游戏界面由m+2行.n列组成.第一行在顶端.一个球会从第一行的某一列出发 ...
- pandas读取各类sql数据源
大数据分析中,我们经常需要使用pandas工具读取各类数据源并将结果保存到数据库中. 本文总结了一些读取和写入常用数据库数据的一些方法,包括mysql,oracle,impala等. 其中读取数据库数 ...
- ionic2 +Angular 使用自定义图标
结合阿里巴巴矢量图标库实现在ionic2开发中使用自定义图标. step1:在阿里巴巴图标管理中新建项目,并添加自己选中的图标到购物车: step2:将购物车中的图标"添加至项目" ...
- Java多线程应用总结
一.基本方法 进程和线程一样,都是实现并发的一个基本单位.线程是比进程更小的执行单位,线程是在进程的基础上进行的进一步划分.所谓多线程,是指一个进程在执行过程中可以产生多个更小的程序单元,这些更小的单 ...
- Zabbix Agent active主动模式监控
zabbix_server端当主机数量过多的时候,由Server端去收集数据,Zabbix会出现严重的性能问题,主要表现如下: 1.当被监控端到达一个量级的时候,Web操作很卡,容易出现502 2.图 ...
- 如何知道你的linux是什么时候安装的
在安装系统时,每个分区下都会有一个 lost+found,而且这个目录的创建时间是和该分区创建的时间一样的.所以如果想知道你的系统是什么时候安装的,只需要看这个目录的创建时间即可. 通常情况下,我们分 ...