码迷,mamicode.com
首页 > 其他好文 > 详细

序列变换

时间:2018-12-05 22:31:17      阅读:248      评论:0      收藏:0      [点我收藏+]

标签:多少   algorithm   ide   href   bsp   class   output   blank   source   

序列变换

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:\n%d\n",++co,n-cnt);
31     }
32     return 0;
33 }
View Code

 

序列变换

标签:多少   algorithm   ide   href   bsp   class   output   blank   source   

原文地址:https://www.cnblogs.com/Fighting-sh/p/10073725.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!