• HDU 1087 Super Jumping! Jumping! Jumping!


    Problem Description
    Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.



    The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
    Your task is to output the maximum value according to the given chessmen list.
     
    Input
    Input contains multiple test cases. Each test case is described in a line as follow:
    N value_1 value_2 …value_N 
    It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
    A test case starting with 0 terminates the input and this test case is not to be processed.
     
    Output
    For each case, print the maximum according to rules, and one line one case.
     
    Sample Input
    3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
     这个题N的范围太小了,N应该为1000000,这样的话,我想就不会有那么多人能过这个题了啊
    #include<iostream>
    #include<cstdio>
    #include<map>
    #include<algorithm>
    using namespace std;
    const int maxn=1000001;
    const long long inf=-99999999999999999;
    map<long long,long long>s;
    typedef map<long long,long long>::iterator Itr;
    long long a[maxn],m[maxn];
    long long solve(int n)
    {
        for (int i=0;i<=n;i++) m[i]=inf;
        long long ans=inf;
        s.clear();
        for (int i=1;i<=n;i++)
        {
            Itr itr=s.lower_bound(a[i]);
            if(s.size()==0)
            {
                m[i]=a[i];
            }
            else
            {
                if(itr==s.begin())
                {
                    m[i]=a[i];
                }
                else
                {
                    long long temp=(--itr)->second;
                    m[i]=a[i]+(temp>0?temp:0);
                }
            }
            itr=s.lower_bound(a[i]);
            while(itr!=s.end() && itr->second<=m[i])
            {
                s.erase(itr);
                itr=s.lower_bound(a[i]);
            }
            s[a[i]]=m[i];
            if(m[i]>ans) ans=m[i];
        }
        return ans;
    }
    int main()
    {
        int m;
        while(scanf("%d",&m)!=EOF && m)
        {
            for (int i=1;i<=m;i++)
            scanf("%lld",&a[i]);
            long long sum=solve(m);
            printf("%lld
    ",sum);
        }
        return 0;
    }

    我的程序适合于N为1000000的时候

    Sample Output
    4 10 3
    至少做到我努力了
  • 相关阅读:
    关于xampp 集成开发包电脑重启mysql无法启动的问题
    ThinkPhP html原样入库
    java 获取图片大小(尺寸)
    xampps 不能配置非安装目录虚拟主机解决方案
    从0开始 java 网站开发(jsp)【1】
    Hello world!
    SpringMVC归纳-1(model数据模型与重定向传参技术)
    TTL与非门电路分析
    git入门手册:git的基本安装,本地库管理,远程上传
    实现简单的评论区功能
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3685614.html
Copyright © 2020-2023  润新知