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
    至少做到我努力了
  • 相关阅读:
    如何用密码保护共享文件?
    如何让光驱自动弹出和关闭?
    欢迎参加“诊断 Windows 7 启动及登录缓慢问题”在线技术会议
    谁偷走了我的系统资源?
    修改Windows验证的登陆框为页面
    使用Fiddler提高前端工作效率
    对非管理员隐藏Site Actions的菜单
    C#多线程参数传递
    转:管理网站集所使用的内容数据库
    转:十步骤让你轻松提升SharePoint性能
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3685614.html
Copyright © 2011-2022 走看看