• 51nod 1294 修改数组


    1294 修改数组
    基准时间限制:1 秒 空间限制:131072 KB 
    给出一个整数数组A,你可以将任何一个数修改为任意一个正整数,最终使得整个数组是严格递增的且均为正整数。问最少需要修改几个数?
    Input
    第1行:一个数N表示序列的长度(1 <= N <= 100000)。
    第2 - N + 1行:每行1个数,对应数组元素。(0 <= A[i] <= 10^9)
    Output
    输出最少需要修改几个数使得整个数组是严格递增的。
    Input示例
    5
    1
    2
    2
    3
    4
    Output示例
    3
    位置的考虑也很重要。
     1 #include<iostream>
     2 #include<algorithm>
     3 #include<cstdio>
     4 #include<cstring>
     5 #include<cmath>
     6 #include<cstdlib>
     7 #include<vector>
     8 using namespace std;
     9 typedef long long ll;
    10 typedef long double ld;
    11 typedef pair<int,int> pr;
    12 const double pi=acos(-1);
    13 #define rep(i,a,n) for(int i=a;i<=n;i++)
    14 #define per(i,n,a) for(int i=n;i>=a;i--)
    15 #define Rep(i,u) for(int i=head[u];i;i=Next[i])
    16 #define clr(a) memset(a,0,sizeof(a))
    17 #define pb push_back
    18 #define mp make_pair
    19 #define fi first
    20 #define sc second
    21 #define pq priority_queue
    22 #define pqb priority_queue <int, vector<int>, less<int> >
    23 #define pqs priority_queue <int, vector<int>, greater<int> >
    24 #define vec vector
    25 ld eps=1e-9;
    26 ll pp=1000000007;
    27 ll mo(ll a,ll pp){if(a>=0 && a<pp)return a;a%=pp;if(a<0)a+=pp;return a;}
    28 ll powmod(ll a,ll b,ll pp){ll ans=1;for(;b;b>>=1,a=mo(a*a,pp))if(b&1)ans=mo(ans*a,pp);return ans;}
    29 void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
    30 //void add(int x,int y,int z){ v[++e]=y; next[e]=head[x]; head[x]=e; cost[e]=z; }
    31 int dx[5]={0,-1,1,0,0},dy[5]={0,0,0,-1,1};
    32 ll read(){ ll ans=0; char last=' ',ch=getchar();
    33 while(ch<'0' || ch>'9')last=ch,ch=getchar();
    34 while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
    35 if(last=='-')ans=-ans; return ans;
    36 }
    37 const int N=100005;
    38 int a[N],b[N];
    39 int main(){
    40     int n=read(),nu=0;
    41     for (int i=1;i<=n;i++) a[i]=read(),a[i]-=i;
    42     for (int i=1;i<=n;i++)
    43     if (a[i]>=0){
    44         int p=upper_bound(b+1,b+nu+1,a[i])-b;
    45         if (p>nu) b[++nu]=a[i];
    46         else b[p]=a[i];
    47     }
    48     printf("%d",n-nu);
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    翻译:Razor剖析之第4部分:Razor页面
    学习第二十二天
    jQuery:选择器和事件
    学习第二十天@简单json+上传文件+Ado存储过程
    统计指定时间段内的周未(非周未)天数
    c#动态创建内存模型(笔记)
    cmd命令 任务计划 详解
    BAT教程:第四节(批处理中的变量)
    103个Windows XP运行命令
    BAT教程 :第二节(for命令详解 )
  • 原文地址:https://www.cnblogs.com/SXia/p/7635318.html
Copyright © 2020-2023  润新知