zoukankan      html  css  js  c++  java
  • @[TOC](硬核の暴力)

    @

    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≤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+1);
    		printf("1 %d 500000
    ",n);//先全部加500000
    		for(int i = 1; i<=n; i++) a[i] += 500000;
    		for(int i = 1; i<=n; i++) {
    			printf("2 %d %lld
    ",i,a[i]-i);
    		}
    		return 0 ;
    	 }
    

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

    思维の锻炼

  • 相关阅读:
    使用SpringSecurityOAuth2默认实现OAuth2授权示例
    Session与Token认证方式的区别
    OAuth协议简介
    MySQL5.7开启binlog日志,及数据恢复简单示例
    MySQL5.X给远程用户授权
    MySQL5.X安装
    MySQL8.0以上创建用户,并授权远程连接
    退役了
    2019牛客国庆day3-G &CF1238E
    luoguP4197:Peaks(Kruskal重构树+主席树)或者(点分树+离线)
  • 原文地址:https://www.cnblogs.com/--ChenShou--/p/10802016.html
Copyright © 2011-2022 走看看