Maxim and Array CodeForces - 721D (贪心)
大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值
贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值
- #include <iostream>
- #include <algorithm>
- #include <cstdio>
- #include <math.h>
- #include <set>
- #include <map>
- #include <queue>
- #include <string>
- #include <string.h>
- #include <bitset>
- #define REP(i,a,n) for(int i=a;i<=n;++i)
- #define PER(i,a,n) for(int i=n;i>=a;--i)
- #define hr putchar(10)
- #define pb push_back
- #define lc (o<<1)
- #define rc (lc|1)
- #define mid ((l+r)>>1)
- #define ls lc,l,mid
- #define rs rc,mid+1,r
- #define x first
- #define y second
- #define io std::ios::sync_with_stdio(false)
- #define endl '\n'
- using namespace std;
- typedef long long ll;
- typedef pair<int,int> pii;
- const int P = 1e9+7, INF = 0x3f3f3f3f;
- ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
- ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
- ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
- //head
- const int N = 1e6+10;
- int n, k, x;
- struct _ {
- ll w;
- int id;
- bool operator < (const _ &rhs) const {
- return abs(w) > abs(rhs.w);
- }
- } e[N];
- ll ans[N];
- int sgn(ll x) {return x<0?-1:1;}
- int main() {
- scanf("%d%d%d", &n, &k, &x);
- int f = 0;
- REP(i,1,n) scanf("%lld", &e[i].w), e[i].id=i, f^=e[i].w<0;
- if (!f) {
- _ *r = max_element(e+1,e+1+n);
- if (!r->w) --k,r->w-=x;
- else {
- int ff = sgn(r->w);
- while (k) {
- r->w -= sgn(r->w)*x, --k;
- if (sgn(r->w)!=ff) break;
- }
- }
- }
- priority_queue<_> q;
- REP(i,1,n) q.push(e[i]);
- while (k) {
- _ t = q.top(); q.pop();
- t.w += sgn(t.w)*x;
- q.push(t), --k;
- }
- while (q.size()) ans[q.top().id]=q.top().w,q.pop();
- REP(i,1,n) printf("%lld ", ans[i]);hr;
- }
Maxim and Array CodeForces - 721D (贪心)的更多相关文章
- 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 F. Maxim and Array(构造贪心)
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces 721D [贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张. 题意: 给一列数a,可以进行k次操作,每次操作可以选取任意一个数加x或者减x,x是固定的数.求如何才能使得这个数列所有数乘积最小. 思路: 贪心...讨 ...
- Artem and Array CodeForces - 442C (贪心)
大意: 给定序列$a$, 每次任选$a_i$删除, 得分$min(a_{i-1},a_{i+1})$(无前驱后继时不得分), 求最大得分. 若一个数$x$的两边都比$x$大直接将$x$删除, 最后剩余 ...
- CodeForces - 721D 贪心+优先队列(整理一下优先队列排序情况)
题意: 给你一个长度为n的数组,你可以对其中某个元素加上x或者减去x,这种操作你最多只能使用k次,让你输出操作后的数组,且保证这个数组所有元素的乘积尽可能小 题解: 在这之前我们要知道a*b>a ...
- 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 —— 贪心
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds ...
- Greg and Array CodeForces 296C 差分数组
Greg and Array CodeForces 296C 差分数组 题意 是说有n个数,m种操作,这m种操作就是让一段区间内的数增加或则减少,然后有k种控制,这k种控制是说让m种操作中的一段区域内 ...
- CodeForces - 721D Maxim and Array (贪心)
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea ...
随机推荐
- win10中命令操作Zookeeper
目录 zk客户端命令: 连接: 命令: 四字命令: 常用命令: 返回参数说明: 参考: zk客户端命令: 连接: C:\Users\qhong\Desktop $ zkCli.cmd -server ...
- 枚举+排序|神奇算式|2014年蓝桥杯A组题解析第三题-fishers
标题:神奇算式 由4个不同的数字,组成的一个乘法算式,它们的乘积仍然由这4个数字组成. 比如: 210 x 6 = 1260 8 x 473 = 3784 27 x 81 = 2187 都符合要求. ...
- 160CrackMe练手 001
peid判断无壳,打开输入伪码注册,根据报错od查找字符串 接下来定位到字符串周边代码 0042FA15 |. 8D55 F0 lea edx,[local.4] 0042FA18 |. 8B83 D ...
- js 二叉树删除最大值和最小值
//删除最小值function delMinNode (root){ if(!root) { return false; } var current = root; if (current.left ...
- P4720 【模板】扩展卢卡斯
思路 扩展Lucas和Lucas定理其实没什么关系 我们要求的是这样的一个问题 \[ \left(\begin{matrix}n\\m\end{matrix}\right) mod\ P \] p不一 ...
- P2633 Count on a tree
思路 运用树上差分的思想,转化成一个普通的主席树模型即可求解 代码 #include <cstdio> #include <algorithm> #include <cs ...
- 论文笔记之 SST: Single-Stream Temporal Action Proposals
SST: Single-Stream Temporal Action Proposals 2017-06-11 14:28:00 本文提出一种 时间维度上的 proposal 方法,进行行为的识别.本 ...
- Java中sort实现降序排序
利用Collections的reverseOrder方法: import java.util.Arrays; import java.util.Collections; public class Ma ...
- (转载)Windows下小狼毫输入法(Rime)的安装与配置(含导入搜狗词库)
div id="cnblogs_post_body" class="blogpost-body"> 最近彻底烦透了搜狗拼音输入法的各种流氓行为,自动升级不 ...
- Java基础【冒泡、选择排序、二分查找】
冒泡排序的思路就是前一个和后一个进行比较,如果大的就交换位置 大的数字后浮 如 12 8 5 31 第一轮 8 5 12 31 第二轮 5 8 ...