传送门

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. mac 电脑 打开隐藏文件

    command +shift +. 第一次是打开,第二次是关闭

  2. SpringBoot标签之@ConfigurationProperties、@PropertySource注解的使用

    当获取主配置文件中属性值时,只需@ConfigurationProperties(prefix = "person")注解来修饰某类,其作用是告诉springBoot,此类中的属性 ...

  3. python数据结构与算法第十六天【贪心算法与动态规划】

    对于一个字符串,对字符串进行分割,分割后的每个子字符串都为回文串,求解所有可行的方案 这个问题可以使用贪心算法与动态规划来求解 步骤如下: (1)先得出所有的单个字符的回文串,单个字符必定是回文串, ...

  4. DELPHI中MDI子窗口的关闭 和打开

    Delphi中MDI子窗口的关闭方式默认为缩小而不是关闭,所以当你单击子窗口右上角的关闭按钮时会发觉该子窗口只是最小化,而不是你预期的那样被关闭.解决办法是在子窗口的OnClose事件处理过程中加入如 ...

  5. Log4j2配置与使用

    依赖包: <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> <depend ...

  6. Servlet3.0上传

    1.上传对表单限制 *method=post *Enctype=multipart/form-data,它的默认值是:application/x-www-form-urlencoded 表单中需要添加 ...

  7. How to install Lion on PC

    open 'InstallESD.dmg' open '/Volumes/Mac OS X Install ESD/BaseSystem.dmg' rm '/Volumes/Mac OS X Base ...

  8. Editor markdown编辑器

    代码示例网址:http://pandao.github.io/editor.md/examples/index.html 引入文件 <link rel="stylesheet" ...

  9. 洛谷P1916 小书童——蚂蚁大战

    题目背景 小A在你的帮助下,开始“刷题”,他在小书童里发现了一款叫“蚂蚁大战”(又称蛋糕保卫战)的游戏.(你懂得) 题目描述 游戏中会出现n只蚂蚁,分别有a1,a2……an的血量,它们要吃你的蛋糕.当 ...

  10. Codeforces 719A 月亮

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6395221.html A. Vitya in the Countryside time limit ...