BZOJ 1609

样例敢不敢再坑一点??

居然样例把解法给透露了!

求LIS和LDS

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cmath>
#include <vector>
#include <deque>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define CLR(x,n) memset(x,n,sizeof(x))
#define PN printf("\n")
#define read(x) scanf("%d",&x)
#define read2(x,y) scanf("%d%d",&x,&y)
#define read3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define write(x) printf("%d",x)
#define write1(x) printf("%d ",x)
#define writeln(x) printf("%d\n",x)
#define write2(x,y) printf("%d %d",x,y)
#define writeln2(x,y) printf("%d %d\n",x,y)
#define write3(x,y,z) printf("%d %d %d",x,y,z)
#define writeln3(x,y,z) printf("%d %d %d\n",x,y,z)
#define INF 1<<30
using namespace std;
void renew(int &x,int y){
    if (x<y)x=y;}
int a[30010],ans1,ans2,d[30010],g[30010];
int cmp1(int a,int b){return a<=b;}
int cmp2(int a,int b){return a>=b;}
int main()
{
    int n;read(n);ans1=ans2=0;
    REP1(i,n)read(a[i]);
    REP1(i,n)g[i]=INF;
    REP1(i,n){
        //REP1(j,n)write1(g[j]);PN;
        int k=lower_bound(g+1,g+n+1,a[i],cmp1)-g;
        d[i]=k;renew(ans1,d[i]);
        g[k]=a[i];
    }//writeln(ans1);REP1(i,n)write1(d[i]);PN;
    REP1(i,n)g[i]=-INF;
    REP1(i,n){
        //REP1(j,n)write1(g[j]);PN;
        int k=lower_bound(g+1,g+n+1,a[i],cmp2)-g;
        d[i]=k;renew(ans2,d[i]);
        g[k]=a[i];
    }//writeln(ans2);REP1(i,n)write1(d[i]);
    writeln(n-max(ans1,ans2));
    system("pause");
    return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值