传送门

https://www.cnblogs.com/violet-acmer/p/10068786.html

题意:

  给定一个长度为 n 的数组a[ ],并且有两种操作:

  ①将前 i 个数全都加上 x;

  ②将前 i 个数全都 mod x

  要求用不超过 n+1 次操作,使得数组 a[ ] 严格单调递增。

题解:

  预备知识补充:

  假设 a > b,在什么条件下可以使式子 a%(a-b) == b 成立 ?

  只有当 a > 2*b 时才成立。

  证明如下:

  用反证法,假设 a < 2*b,那么 b > a/2。

  

  如果 a > 2*b 呢?

  

  根据题干要求,x 最大可取 1e6 ,而 i 最大才 2000 ,所以可以通过上述公式使数组 a[ i ]=i;

  步骤:

    (1):数组a[ ] 全部加上一个较大的数 maxNum(maxNum+a[i] > 2*i , 最极端的情况就是 i = 2000,a[i]=0,那么只需让 maxNum = 40001就行了);

    (2):对于操作(1)后的每个数a[ i ],实施操作 a[ i ]%( a[ i ]-i ),使a[ i ] = i,最终序列便是 1~n 的排列,当然严格单调递增啦。

AC代码:

 #include<iostream>
#include<cstdio>
using namespace std;
const int maxn=+; int n;
int a[maxn];
int maxNum=; void Solve()
{
printf("%d\n",n+);//共进行了 n+1 次操作
printf("%d %d %d\n",,n,maxNum);
for(int i=;i <= n;++i)
printf("%d %d %d\n",,i,maxNum+a[i]-i);
}
int main()
{
scanf("%d",&n);
for(int i=;i <= n;++i)
scanf("%d",a+i);
Solve();
}

Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task的更多相关文章

  1. Codeforces Round #525 (Div. 2) F. Ehab and a weird weight formula

    F. Ehab and a weird weight formula 题目链接:https://codeforces.com/contest/1088/problem/F 题意: 给出一颗点有权值的树 ...

  2. Codeforces Round #525 (Div. 2)E. Ehab and a component choosing problem

    E. Ehab and a component choosing problem 题目链接:https://codeforces.com/contest/1088/problem/E 题意: 给出一个 ...

  3. Codeforces Round #525 (Div. 2)D. Ehab and another another xor problem

    D. Ehab and another another xor problem 题目链接:https://codeforces.com/contest/1088/problem/D Descripti ...

  4. Codeforces Round #525 (Div. 2)B. Ehab and subtraction

    B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...

  5. Codeforces Round #525 (Div. 2)A. Ehab and another construction problem

    A. Ehab and another construction problem 题目链接:https://codeforc.es/contest/1088/problem/A 题意: 给出一个x,找 ...

  6. Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task 数学 mod运算的性质

    C. Ehab and a 2-operation task 数学 mod运算的性质 题意: 有两种对前缀的运算 1.对前缀每一个\(a +x\) 2.对前缀每一个\(a\mod(x)\) 其中x任选 ...

  7. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(待完成)

    参考资料: [1]:https://blog.csdn.net/weixin_43790474/article/details/84815383 [2]:http://www.cnblogs.com/ ...

  8. Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学

    题意:给出树 求最大的sigma(a)/k k是选取的联通快个数   联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值  这里先要满足最大平均值  而首先要满足最大  也就是一个数的时候可 ...

  9. Codeforces Round #525 (Div. 2) D. Ehab and another another xor problem(交互题 异或)

    题目 题意: 0≤a,b<2^30, 最多猜62次. 交互题,题目设定好a,b的值,要你去猜.要你通过输入 c d : 如果 a^c < b^d ,会反馈 -1 : 如果 a^c = b^ ...

随机推荐

  1. npm 设置代理

    设置代理 npm config set proxy http://username:password@server:portnpm config set https-proxy http://user ...

  2. MySQL 优化小技巧

    碎片整理: mysql数据一开始是在磁盘上顺序存放的,如果数据表有频繁的update改动,那么数据就会形成很多碎片,拖慢速度和不利于索引: 优化碎片有两种方式: alter table user en ...

  3. Windows Server 2012 添加角色时出现 failed to open runspace pool

    先把所有的Windows Server 2012的更新更新了.再来添加服务器角色.就不会再出现 The Server Manager WinRM plug-in might be corrupted ...

  4. codeforces492C

    Vanya and Exams CodeForces - 492C Vanya wants to pass n exams and get the academic scholarship. He w ...

  5. 前端bug记录

    记录一下前端入门时期遇到的一些bug. 1.同步.异步问题 背景:Javascript语言的执行环境是单线程.即一次只能完成一个任务.若有多个任务则需排队逐个执行——前一个任务完成,再执行后一个任务. ...

  6. AHOI(十二省联考)2019 退役记

    我也想退役失败.jpg Day 0 我才知道联考原来是4.5h? 下午居然还有讲题,感觉变得正规多了. 试机敲了LCT,NTT,SA,加起来花了大概40min,基本1A,感觉海星.键盘似乎有点过于灵敏 ...

  7. WEB请求处理

    https://blog.csdn.net/bpingchang/article/details/51328941

  8. verilog parameter 位宽问题

    前言 一直以为parameter 的位宽是无限的,其实不然. 流程: 仿真一下就知道啦: 用处: 精准控制位宽理论上会占用更少的内存,其他好像并没有什么卵用,注意不要越界,我这里系统默认32bit位宽 ...

  9. ios-deploy was not found

    Ionic 打包ios的时候,突然报错,提示如下: (node:1157) UnhandledPromiseRejectionWarning: ios-deploy was not found. Pl ...

  10. linux 开放80端口

    必须确保两块都开放 1.云服务器-->安全组开放 比如百度云服务器: 2.linux内置防火墙开放 注意:此处如果不设置开放,即时云端开放了也没用,如果同时存在  80 (拒绝) 80(允许)  ...