zoukankan      html  css  js  c++  java
  • 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
    至少做到我努力了
  • 相关阅读:
    MySQL数据库的完全备份与恢复
    MySQL数据库之索引、事务、存储引擎详细讲解
    LNMP架构介绍与部署
    Haproxy搭建Web集群
    LAMP环境之MySQL服务安装详细过程
    MySQL主从复制详解
    LAMP环境之编译安装httpd服务
    搭建yum软件仓库,让你维护轻松自如
    Shell脚本一键安装Samba服务
    Shell脚本之冒泡排序
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3685614.html
Copyright © 2011-2022 走看看