zoukankan      html  css  js  c++  java
  • HDU 5773The All-purpose Zero

    The All-purpose Zero

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 231    Accepted Submission(s): 101


    Problem Description
    ?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increasing (strictly) subsequence he can get.
     
    Input
    The first line contains an interger T,denoting the number of the test cases.(T <= 10)
    For each case,the first line contains an interger n,which is the length of the array s.
    The next line contains n intergers separated by a single space, denote each number in S.
     
    Output
    For each test case, output one line containing “Case #x: y”(without quotes), where x is the test case number(starting from 1) and y is the length of the longest increasing subsequence he can get.
     
    Sample Input
    2
    7
    2 0 2 1 2 0
    5
    6 1 2 3 3 0 0
     
    Sample Output
    Case #1: 5
    Case #2: 5
    Hint
    In the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.
     
    0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。
    为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的。
    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/7/28 15:51:43
    File Name     :p410.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 100010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int d[maxn];
    int a[maxn];
    int main()
    {
        #ifndef ONLINE_JUDGE
        freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        int T,n,cnt;
        cin>>T;
        for(int t=1;t<=T;t++){
            cin>>n;
            for(int i=1;i<=n;i++)scanf("%d",&a[i]);
            int len=0;
            cnt=0;
            for(int i=1;i<=n;i++){
                if(a[i]==0)cnt++;
                else {
                    a[i]-=cnt;
                    int pos=lower_bound(d,d+len,a[i])-d;
                    if(pos==len){
                        d[len++]=a[i];
                    }
                    else d[pos]=a[i];
                }
            }
            printf("Case #%d: %d
    ",t,len+cnt);
        }
        return 0;
    }
  • 相关阅读:
    离线获取docker镜像(docker save vs load)&docker export vs import& docker commit
    深入分析JavaWeb的中文编码问题
    python中Django的基本使用
    element+springboot实现简单的商品管理
    springboot+thymeleaf自定义标签
    springboot整合shiro
    linux的namespace、docker网络模式
    Docker Compose、Swarm 集群管理
    iOS Share Extension 自定义分享界面
    Mixin Messenger 源码解读 1 — — WCDB Swift
  • 原文地址:https://www.cnblogs.com/pk28/p/5716049.html
Copyright © 2011-2022 走看看