HDU 1087 Super Jumping! Jumping! Jumping!
2014-04-24 15:20
344 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, print the maximum according to rules, and one line one case.
[align=left]Sample Input[/align]
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
这个题N的范围太小了,N应该为1000000,这样的话,我想就不会有那么多人能过这个题了啊
我的程序适合于N为1000000的时候
[align=left]Sample Output[/align]
4
10
3
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each case, print the maximum according to rules, and one line one case.
[align=left]Sample Input[/align]
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\n",sum); } return 0; }
我的程序适合于N为1000000的时候
[align=left]Sample Output[/align]
4
10
3
相关文章推荐
- AJAX组件-dwr 的部署与实现
- MFC中文档/视图类结构内的相互调用方法总结
- android std::string(NULL) crash
- objective-c语法
- 【新技术】笔记本无线充电
- 美工与程序员的Web工作如何做到相对分离?
- 设计推荐系统
- 2014 JAVA软件工程师发展趋势
- SQL SERVER 2005/2008全文索引实战讲解
- Hangover
- [z]JSONP例子
- hdoj 2209 翻纸牌游戏(BFS + 位运算)
- iMatrix平台的发展史
- zookeeper watcher方案
- ural1519之插头DP
- 在Tomcat下部署java web项目的简单方法步骤
- python string模块
- Giraph源码分析(七)—— 添加消息统计功能
- phpcms栏目调用详解
- 1-9输出所有解