zoukankan      html  css  js  c++  java
  • 序列变换

    序列变换

    http://acm.hdu.edu.cn/showproblem.php?pid=5256

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 2845    Accepted Submission(s): 928


    Problem Description
    我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增。其中无论是修改前还是修改后,每个元素都必须是整数。
    请输出最少需要修改多少个元素。
     
    Input
    第一行输入一个T(1T10),表示有多少组数据

    每一组数据:

    第一行输入一个N(1N105),表示数列的长度

    第二行输入N个数A1,A2,...,An

    每一个数列中的元素都是正整数而且不超过106
     
    Output
    对于每组数据,先输出一行

    Case #i:

    然后输出最少需要修改多少个元素。
     
    Sample Input
    2
    2
    1 10
    3
    2 5 4
     
    Sample Output
    Case #1:
    0
    Case #2:
    1
     
    Source
     1 #include <cstring>
     2 #include <cstdio>
     3 #include <cmath>
     4 #include <algorithm>
     5 #include <iostream>
     6 using namespace std;
     7 const int K=100000+9;
     8 int a[K],c[K];
     9 int main()
    10 {
    11     int n,cnt;
    12     int t;
    13     scanf("%d",&t);
    14     int  co=0;
    15     while(t--)
    16     {
    17         scanf("%d",&n);
    18         cnt=0;
    19         for(int i=0;i<=n;i++) c[i]=0;
    20         for(int i=1; i<=n; i++){
    21             scanf("%d",&a[i]);
    22             a[i]-=i;
    23         }
    24         for(int i=1;i<=n;i++)
    25         {
    26             int d=upper_bound(c+1,c+1+cnt,a[i])-c;
    27             c[d]=a[i];
    28             cnt=max(cnt,d);
    29         }
    30         printf("Case #%d:
    %d
    ",++co,n-cnt);
    31     }
    32     return 0;
    33 }
    View Code
  • 相关阅读:
    笔记-树形dp
    20181018 考试记录
    20181015 考试记录&数论
    [模板]2-SAT 问题&和平委员会
    FLask的偏函数应用
    Flask中的g到底是个什么鬼?
    Flask源码关于local的实现
    Flask的“中间件”
    Flask之模板
    FLask之视图
  • 原文地址:https://www.cnblogs.com/Fighting-sh/p/10073725.html
Copyright © 2011-2022 走看看