ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

@[TOC](硬核の暴力)

2019-05-02 12:43:35  阅读:413  来源: 互联网

标签:operations 暴力 output second input TOC array 求余 硬核


目录

@(硬核の暴力)

Math --CodeForces - 1062B

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≤10^6^), and replace a~j~ with a~j~+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≤10^6^), and replace a~j~ with a~j~%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≤10^5^), 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

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

技不如人,智不如人

看到的都是统一的方法

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

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

思维の锻炼

标签:operations,暴力,output,second,input,TOC,array,求余,硬核
来源: https://www.cnblogs.com/--ChenShou--/p/10802016.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有