sicily 1176. Two Ends
来源:互联网 发布:centos zip 压缩 编辑:程序博客网 时间:2024/05/21 07:02
1176. Two Ends
Constraints
Time Limit: 1 secs, Memory Limit: 64 MB
Description
In the two-player game "Two Ends", an even number of cards is laid out in a row. On each card, face up, is written a positive integer. Players take turns removing a card from either end of the row and placing the card in their pile. The player whose cards add up to the highest number wins the game. Now one strategy is to simply pick the card at the end that is the largest -- we'll call this the greedy strategy. However, this is not always optimal, as the following example shows: (The first player would win if she would first pick the 3 instead of the 4.)
3 2 10 4
You are to determine exactly how bad the greedy strategy is for different games when the second player uses it but the first player is free to use any strategy she wishes.
Input
There will be multiple test cases. Each test case will be contained on one line. Each line will start with an even integer n followed by n positive integers. A value of n = 0 indicates end of input. You may assume that n is no more than 1000. Furthermore, you may assume that the sum of the numbers in the list does not exceed 1,000,000.
Output
For each test case you should print one line of output of the form:
In game m, the greedy strategy might lose by as many as p points.
where m is the number of the game (starting at game 1) and p is the maximum possible difference between the first player's score and second player's score when the second player uses the greedy strategy. When employing the greedy strategy, always take the larger end. If there is a tie, remove the left end.
Sample Input
4 3 2 10 48 1 2 3 4 5 6 7 88 2 2 1 5 3 8 7 30
Sample Output
In game 1, the greedy strategy might lose by as many as 7 points.In game 2, the greedy strategy might lose by as many as 4 points.In game 3, the greedy strategy might lose by as many as 5 points.
- Sicily 1176. Two Ends
- sicily 1176.Two ends
- [sicily]1176. Two Ends
- Sicily 1176. Two Ends
- Sicily 1176. Two Ends
- Sicily 1176. Two Ends
- sicily 1176. Two Ends
- sicily 1176. Two Ends
- sicily 1176. Two Ends
- Sicily 1176. Two Ends
- Sicily 1176. Two Ends ---by rupeng
- Sicily 1008 two ends
- Sicily 1176 Two Ends
- sicily 1176 two ends
- Sicily 1176 Two Ends
- sicily 1176 Two ends
- 1176. Two Ends
- 1176. Two Ends
- chrome插件开发杂记
- Objective-C 学习笔记二
- 创建一个sms.db数据库俩面在创建一个message表,插入数据然后在读取数据
- 为什么很多看起来不是很复杂的网站,比如 Facebook 需要大量顶尖高手来开发?
- Eclipse中常用的快捷键
- sicily 1176. Two Ends
- a标签中有点击(onclick)事件
- HIVE 1.1.0 启动时报错: Unsupported major.minor version 51.0
- Unity 加密解密那些事(转载)
- matlab getframe()
- C++ atof函数
- hive升级测试记录
- Struts2返回JSON数据的具体应用范例
- POJ 2031:Building a Space Station 最小生成树