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…
D. Maxim and Array 题目连接: http://codeforces.com/contest/721/problem/D Description Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or…
D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he in…
题目链接:http://codeforces.com/problemset/problem/721/D D. Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He…
题目描述: Maxim and Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer…
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation…
传送门 分析:其实没什么好分析的.统计一下负数个数.如果负数个数是偶数的话,就要尽量增加负数或者减少负数.是奇数的话就努力增大每个数的绝对值.用一个优先队列搞一下就行了. 我感觉这道题的细节极为多,非常复杂,其实是自己智障了.. 我看了一下学长菊苣的代码,好精巧...注释部分是他的代码 /*****************************************************/ //#pragma comment(linker, "/STACK:1024000000,10240…
贪心,优先队列. 先看一下输入的数组乘积是正的还是负的. ①如果是负的,也就是接下来的操作肯定是让正的加大,负的减小.每次寻找一个绝对值最小的数操作就可以了. ②如果是正的,也是考虑绝对值,先操作绝对值最小的那个数,直到那个数字的符号发生变化就停止操作,接下来就是第①步. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #incl…
大意: 给定序列, 每次操作选择一个数+x或-x, 最多k次操作, 求操作后所有元素积的最小值 贪心先选出绝对值最小的调整为负数, 再不断选出绝对值最小的增大它的绝对值 #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #include <queue> #inc…