CodeForces - 1062B——————硬核の暴力

Math

C. Ehab and a 2-operation task

time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output

You’re given an array a of length n. You can perform the following operations on it:

1.choose an index i (1≤i≤n), an integer x (0≤x≤106), and replace aj with aj+x for all (1≤j≤i), which means add x to all the elements in the prefix ending at i.

2.choose an index i (1≤i≤n), an integer x (1≤x≤106), and replace aj with aj%x for all (1≤j≤i), which means replace every element in the prefix ending at i with the remainder after dividing it by x.

Can you make the array strictly increasing in no more than n+1 operations?

Input
The first line contains an integer n (1≤n≤2000), the number of elements in the array a.
The second line contains n space-separated integers a1, a2, …, an (0≤ai≤105), the elements of the array a.

Output
On the first line, print the number of operations you wish to perform. On the next lines, you should print the operations.
To print an adding operation, use the format “1 i x”; to print a modding operation, use the format “2 i x”. If i or x don’t satisfy the limitations above, or you use more than n+1 operations, you’ll get wrong answer verdict.

Examples
input
3
1 2 3
output
0
input
3
7 6 3
output
2
1 1 1
2 2 4

Note
In the first sample, the array is already increasing so we don’t need any operations.
In the second sample:
In the first step: the array becomes [8,6,3].
In the second step: the array becomes [0,2,3].

题目很难,起码对于我来说,第一想法是暴力暴力模拟。
于是乎,按照题目要求的升序,我想到的是,能不能利用数组存储的下标?
也就是说,将里面的元素全部变成和下标有关的数,利用上面的两个操作?

比如 2 3 4 8 5 6 这六个数构成的数组,要怎么操作才能变得和下标一样严格递增?
像是 1 2 3 4 5 6
或者 0 1 2 3 4 5

好的,到此为止,我的智商不够用了,打开百度一顿操作

技不如人,智不如人

看到的都是统一的方法

先加个很大的数
然后利用求余%%%%%求出一片新天地

对于每一个数组元素,我们都可以有以下操作
ai+=100000000;
那么就变成了 100000002 100000003 100000004 100000008 100000005 100000006
然后求余
先让第一个(a0)对100000002-i求余(i=0)
变成了 0 100000003 100000004 100000008 100000005 100000006
然后让前两个a0-a1对100000003-i求余(i=1)
变成 0 1 100000004 100000008 100000005 100000006
然后前三个a0-a2(i=2)
0 1 2 100000008 100000005 100000006

……
………
最后0 1 2 3 4 5
这里刚刚好n+1步!

为什么可以样做?

因为一开始加了一个很大的数100000000
这样后面求余对前面的数没有影响

想出这种方法的都是人才

代码如下

	#include<cstdio>
	#include<iostream>
	using namespace std;
	int main()
	{
		int n,a[2005]={0};
		cin>>n;
		for(int i = 1; i<=n; i++) scanf("%lld",&a[i]); 
		printf("%d\n",n+1);
		printf("1 %d 500000\n",n);//先全部加500000
		for(int i = 1; i<=n; i++) a[i] += 500000;
		for(int i = 1; i<=n; i++) {
			printf("2 %d %lld\n",i,a[i]-i);
		}
		return 0 ;
	 }

蒟蒻就是蒟蒻,学再多奇技淫巧都还是蒟蒻o(╥﹏╥)o

思维の锻炼

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值