C. Ehab and a 2-operation tasktime

C. Ehab and a 2-operation tasktime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou’re given an array aa of length nn. You can perform the following operations on it:choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (0≤x≤106)(0≤x≤106), and replace ajaj with aj+xaj+x for all (1≤j≤i)(1≤j≤i), which means add xx to all the elements in the prefix ending at ii.choose an index ii (1≤i≤n)(1≤i≤n), an integer xx (1≤x≤106)(1≤x≤106), and replace ajaj with aj%xaj%x for all (1≤j≤i)(1≤j≤i), which means replace every element in the prefix ending at ii with the remainder after dividing it by xx.Can you make the array strictly increasing in no more than n+1n+1 operations?InputThe first line contains an integer nn (1≤n≤2000)(1≤n≤2000), the number of elements in the array aa.The second line contains nn space-separated integers a1a1, a2a2, ……, anan (0≤ai≤105)(0≤ai≤105), the elements of the array aa.OutputOn 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 “11 ii xx”; to print a modding operation, use the format “22 ii xx”. If ii or xx don’t satisfy the limitations above, or you use more than n+1operations, you’ll get wrong answer verdict.ExamplesinputCopy3
1 2 3
outputCopy0inputCopy3
7 6 3
outputCopy2
1 1 1
2 2 4
NoteIn 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][8,6,3].In the second step: the array becomes [0,2,3][0,2,3].

#include<bits/stdc++.h>
using namespace std;
int num=1e6,i;
int main()
{
    int a;
    cin>>a;
    cout<<a+1<<endl;
    //cout<<1<<" "<<a<<" "<<1<<endl;
    cout<<2<<" "<<a<<" "<<1<<endl;
    cout<<1<<" "<<a<<" "<<num<<endl;
    while(--a)
    {
        printf("2 %d %d\n",++i,--num);
    }
    return 0;
}

这道题,我没想到1e6会用到,还有n+1,因为是找出存在的解,所以找到一般需要技巧,验证解是否存在,我的常规想法往往是找出最优解,所以会陷入误区,所以存在性问题要会找答案。由于%1所有数都会为0,很特殊,所以直接转化,1e6很大的数也是有 特征的,直接各个加上,模上不超过2000的数,没有影响,又是不超过n+1步,所以直接搞成递增就行了
哇,一看代码,瞬间觉得自己傻叉了,还硬算,如此简洁的代码,还是要充分利用条件的

猜你喜欢

转载自blog.csdn.net/qq_42865713/article/details/84838059