Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task
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的更多相关文章
- 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 题意: 给出一颗点有权值的树 ...
- 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 题意: 给出一个 ...
- 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 ...
- Codeforces Round #525 (Div. 2)B. Ehab and subtraction
B. Ehab and subtraction 题目链接:https://codeforc.es/contest/1088/problem/B 题意: 给出n个数,给出k次操作,然后每次操作把所有数减 ...
- 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,找 ...
- 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任选 ...
- 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/ ...
- Codeforces Round #525 (Div. 2) E. Ehab and a component choosing problem 数学
题意:给出树 求最大的sigma(a)/k k是选取的联通快个数 联通快不相交 思路: 这题和1个序列求最大的连续a 的平均值 这里先要满足最大平均值 而首先要满足最大 也就是一个数的时候可 ...
- 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^ ...
随机推荐
- 多线程的实现方式01 Thread
/* * 多线程 有三种实现方式 * 其一 Thread * * 写一个类 * * 1.让他继承 Thread * 2.重写thread中的run方法 * 3.创建子类对象就是在 创建线程! * 3. ...
- C#中decimal,double和float的区别
float 单精度浮点 32bit,double 双精度浮点64bit,decimal是高精度 128bit,浮点型.float double 是 基本类型(primitive type),decim ...
- 去掉AMD锐龙和Intel Kaby Lake的不支持的硬件的提示
Windows 7和Windows 8.1都不支持AMD Ryzen 锐龙系列和Intel最新的Kaby Lake系列,Windows Update 更新之后总是会提示“不支持的硬件(Unsuppor ...
- JQuery Datatable用法
原文出处:http://sgyyz.blog.51cto.com/5069360/1408251 目标: 使用jQuery Datatable构造数据列表,并且增加或者隐藏相应的列,已达到数据显示要求 ...
- SQL 添加索引
使用CREATE 语句创建索引 CREATE INDEX index_name ON table_name(column_name,column_name) include(score) 普通索引 C ...
- Spring Boot 构建电商基础秒杀项目 (十二) 总结 (完结)
SpringBoot构建电商基础秒杀项目 学习笔记 系统架构 存在问题 如何发现容量问题 如何使得系统水平扩展 查询效率低下 活动开始前页面被疯狂刷新 库存行锁问题 下单操作步骤多,缓慢 浪涌流量如何 ...
- 【python练习题】程序10
#10.题目:暂停一秒输出,并格式化当前时间. import time print(time.time())#timestamp print(time.localtime(time.time()))# ...
- ASP.NET Core Building chat room using WebSocket
Creating “Login form” We use here simple form where user can insert his or her preferred nick name f ...
- windows 动态库的封装以及调用
1.一个程序从源文件编译生成可执行文件的步骤:预编译 --> 编译 --> 汇编 --> 链接(1)预编译,即预处理,主要处理在源代码文件中以“#”开始的预编译指令,如宏展开.处 ...
- windows开关机事件
开关机事件.xml <ViewerConfig> <QueryConfig> <QueryParams> <Simple> <BySource&g ...