One of the most wonderful qualities of an ACMer is to be multi interests so he combines multiple qualifications and hobbies not just coding. Hussain is one of the most qualified ACMers to mention when talking about hobbies and other domains of personality training despite of his qualifications in ACM problem solving and math. It’s very known about Hussain his obsession in hunting and shooting, he used to pass hours training on empty cans in his childhood. These days, Hussain became a professional and still challenge others in this game, but for his bad luck he accidentally challenged a professional ACMer, without mentioning the name, so this ACMer made a game for Hussain. He numbered N targets for Hussain with random numbers and challenged him to shoot the minimum number of targets so the remaining numbers will form a sequence of increasing (by one) numbers in their current order. Example: if there is 6 targets numbered as follow: 2 5 7 3 2 4 Hussain will shoot 5,7 and the second 2 remaining for 2 3 4. Now, Hussain will focus on shooting, we will help him and focus on the targets he must shoot. But No! Hussain is an very good ACMer, we will make it hard for him and just tell him the number of the remaining targets in the sequence.
Input
First line contain an integer T represents the number of test cases 0 < T < 100, each test case consists of two lines, the first one is an integer 0< N < 20000 represents the number of targets, then followed by the second line that contains N numbers each number 0 < Xi < 20000 represents the number written on the i’th target.
Output
For each test case print one number represents the remaining sequence’s length can be created by the input where it should be the maximum length and each number of it follow its previous by 1.
Examples
Input
4
6
2 5 7 3 2 4
7
2 18 65 33 11 5 4
5
2 7 5 9 3
5
9 8 7 10 11
Output
3
1
2
3
Note
Please consider a large input file.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define INF 2x3f3f3f3f
int main()
{
int t,i,num,x,n;
int a[22000];
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
num=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&x);
a[x]=a[x-1]+1;
if(a[x]>num)
num=a[x];
}
printf("%d\n",num);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main()
{
int t,i,num,x,n;
int a[22000];
scanf("%d",&t);
while(t--){
memset(a,0,sizeof(a));
num=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&x);
a[x]=a[x-1]+1;
if(a[x]>num)
num=a[x];
}
printf("%d\n",num);
}
return 0;
}
其实这个题没作对,后来发现,相同的代码,选择不同的语言, 有不同的效果,但是我不知道这是为啥。。
有没有大佬看到可以回复一下…