zoukankan      html  css  js  c++  java
  • Codeforces Round #525 (Div. 2) C. Ehab and a 2-operation task

    题目链接:http://codeforces.com/contest/1088/problem/B  

    题意:给定长度为n的数列,要求在不大于n+1次操作内使该数列严格递增。操作有两种,区间[1,i]内的数加上x,或者区间[1,i]内的数对x取余。

    思路:先给所有数加上一个较大的数M,再让每个数(a[i]+M)对(a[i]+M-i)取余即可。

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 const int M = 100000;
     4 typedef long long ll;
     5 ll a[M];
     6 int main()
     7 {
     8     int n; cin >> n;
     9     for (int i = 1; i <= n; i++) cin >> a[i];
    10     cout << n + 1<<endl;
    11     cout << 1 << " " << n << " " << M <<endl;
    12     for (int i = 1; i <= n; i++) cout << 2 << " " << i << " " << M + a[i] - i << endl;
    13     return 0;
    14 }

    备注:首先是一个结论n%(n-x)=x,之所以要加M,是因为i能取到1e5,所以要保证a[i]足够大,否则会出现对负数取模。其次要注意本题所有数据不能超过1e6,我一开始设M=1e6+7,结果判我WA。

    ————————————————
    心里有光,哪儿都美
  • 相关阅读:
    练字的感悟
    关于简单
    全都是泡沫
    跟着电影环游世界
    12.8《印度之行》
    11.21派生类对基类的访问
    Linux,begin
    如何利用google
    回调函数
    原型对象
  • 原文地址:https://www.cnblogs.com/harutomimori/p/10311007.html
Copyright © 2011-2022 走看看