- 导弹拦截
- 2016-07-19 15:16:11 @
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int i,j,k,n,m,num;
int a[10001],f[10001];
char c;
int find(int t){
int l,r,mid;
l=0;r=num;
while (l<r){
mid=(l+r)/2;
if (f[mid]>t) r=mid;
else l=mid+1;
}
return l;
}
int main()
{
freopen("1.in","r",stdin);
while (~scanf("%d",&a[++i])) scanf("%c",&c);
n=i-1;num=0;f[num]=32767;
for (i=1;i<=n;i++){
if (a[i]<f[num]) {f[++num]=a[i];a[i]=-32767;}
else f[find(a[i])]=a[i];
}
printf("%d,",num);
num=0;f[num]=-32767;
memset(f,0,sizeof f);
for (i=1;i<=n;i++){
if (a[i]>f[num]) {f[++num]=a[i];}
else f[find(a[i])]=a[i];
}
printf("%d\n",num);
}
1 条评论
-
Cookiezi LV 7 @ 2016-07-19 16:14:17
请加上代码高亮
freopen("1.in","r",stdin);
应去掉,其他部分没看
- 1