zoukankan      html  css  js  c++  java
  • [校内自测] Incr (LIS+智商)

    Incr incr

    ##【题目描述】:

    数列 A1,A2,...,AN,修改最少的数字,使得数列严格单调递增。

    ##【输入描述】:

    1 行,1 个整数 N

    2 行,N 个整数 A1,A2,...,AN

    ##【输出描述】:

    1 个整数,表示最少修改的数字

    ##【样例输入】:

    3

    1 3 2

    ##【样例输出】:

    1

    ##【时间限制、数据范围及描述】:

    时间:1s 空间:256M

    对于 50% 的数据,N<=10^3

    对于 100% 的数据,1<=N<=10^5, 1<=Ai<=10^9

    这题mmp思路只有出题人能想的出来……laj今天虽然是rk1但是laj比别人迟10min交,为什么呢?因为laj把很多时间耗在了这一题上(悄咪咪的说其实laj是第二题没想粗来所以滚去想第一题了 _(:зゝ∠)_)

    思路:把原数列的第i位减掉i,然后拿n减掉最长单调不下降子序列的长度 _(:зゝ∠)_

     1 #include "bits/stdc++.h"
     2 using namespace std;
     3 typedef long long LL;
     4 const int MAX=1e5+5;
     5 int n;
     6 int a[MAX],b[MAX],len;
     7 inline int read(){
     8     int an=0,x=1;char c=getchar();
     9     while (c<'0' || c>'9') {if (c=='-') x=-1;c=getchar();}
    10     while (c>='0' && c<='9') {an=an*10+c-'0';c=getchar();}
    11     return an*x;
    12 }
    13 int search(int x){
    14     int low=1,high,mid; high=len;
    15     while (low<=high){
    16         mid=(low+high)>>1;
    17         if (b[mid]>x) high=mid-1;
    18         else low=mid+1;
    19     }
    20     return low;
    21 }
    22 int main(){
    23     freopen ("incr.in","r",stdin);
    24     freopen ("incr.out","w",stdout);
    25     int i,j,zt;
    26     n=read();
    27     for (i=1;i<=n;i++) a[i]=read()-i;
    28     memset(b,0,sizeof(b));
    29     len=1;b[1]=a[1];
    30     for (i=2;i<=n;i++){
    31         zt=search(a[i]);
    32         if (zt>len) len++;
    33         b[zt]=a[i];
    34     }
    35     printf("%d",n-len);
    36     return 0;
    37 }
    未来是什么样,未来会发生什么,谁也不知道。 但是我知道, 起码从今天开始努力, 肯定比从明天开始努力, 要快一天实现梦想。 千里之行,始于足下! ——《那年那兔那些事儿》
  • 相关阅读:
    Wildcard Matching
    【Unity3D游戏开发】NGUI之DrawCall数量 (四)
    POJ1328 Radar Installation 【贪心&#183;区间选点】
    [C/C++标准库]_[0基础]_[怎样实现std::string自己的Format(sprintf)函数]
    Android程序崩溃异常收集框架
    括号配对问题
    android dp 和 px 的相互转换
    freemarker写select组件报错总结(四)
    [redis]redis概述
    oracle数据库权限管理
  • 原文地址:https://www.cnblogs.com/keximeiruguo/p/7689357.html
Copyright © 2011-2022 走看看