Python——【USACO 3.3.5】——A Game
来源:互联网 发布:社保政府补贴数据 编辑:程序博客网 时间:2024/06/05 22:41
IOI'96 - Day 1
Consider the following two-player game played with a sequence of N positive integers (2 <= N <= 100) laid onto a 1 x N game board. Player 1 starts the game. The players move alternately by selecting a number from either the left or the right end of the gameboard. That number is then deleted from the board, and its value is added to the score of the player who selected it. A player wins if his sum is greater than his opponents.
Write a program that implements the optimal strategy. The optimal strategy yields maximum points when playing against the "best possible" opponent. Your program must further implement an optimal strategy for player 2.
PROGRAM NAME: game1
INPUT FORMAT
Line 1:N, the size of the boardLine 2-etc:N integers in the range (1..200) that are the contents of the game board, from left to rightSAMPLE INPUT (file game1.in)
64 7 2 95 2
OUTPUT FORMAT
Two space-separated integers on a line: the score of Player 1 followed by the score of Player 2.SAMPLE OUTPUT (file game1.out)
18 11
N个正整数的序列,由玩家1开始,两人轮流从序列的任意一端取一个数,取数后该数字被去掉并累加到本玩家的得分中,当数取尽时,游戏结束。以最终得分多者为胜。编一个执行最优策略的程序,最优策略就是使玩家在与最好的对手对弈时,能得到的在当前情况下最大的可能的总分的策略。程序要始终为第二位玩家执行最优策略。
"""ID : mcdonne1LANG : PYTHONTASK : game1"""fin = open ('game1.in', 'r')fout = open ('game1.out', 'w')num = [0 for i in range (110)]tot = [0 for i in range (110)]f = [[0 for i in range (110)] for j in range (110)]r = fin.readline()n = int(r)cnt = 0while cnt < n :r = fin.readline().split()for i in range (len(r)) :cnt += 1num[cnt] = int(r[i])f[cnt][cnt] = num[cnt]tot[cnt] = tot[cnt - 1] + num[cnt]for i in range (n)[::-1]:for j in range (i + 1, n + 1) :f[i][j] = max (tot[j] - tot[i] - f[i + 1][j] + num[i], tot[j - 1] - tot[i - 1] - f[i][j - 1] + num[j])fout.write (str(f[1][n]) + ' ' + str(tot[n] - f[1][n]) + '\n')fin.close()fout.close()
阅读全文
0 0
- Python——【USACO 3.3.5】——A Game
- usaco 3.3 A Game
- USACO 3.3 A Game
- 【USACO题库】3.3.5 A Game游戏
- USACO Section 3.3 A Game
- USACO 3.3 A Game (game1)
- USACO--3.3A Game+dp
- C++——【USACO 4.3.3】——Letter Game
- usaco Chapter 3 section 3.3 A game
- USACO Section 3.3 A Game - DP而已~
- USACO section 3.3 A Game(DP)
- USACO 3.3 A Game游戏 (DP)
- USACO Section 3.3 A Game pascal
- usaco A Game
- usaco training-A Game
- USACO 3.4 A Game
- usaco --A Game--game1
- usaco A game
- STL中map和string, vector 用法详解
- SpringMVC hibernate整合时jsp中引用文件问题
- js的单线程和异步
- js attr prop is 的使用
- CrossLight.Pics3D.v2003.12.3.2004.1.8WinALL(激光二极管3D模拟器,好用!)\
- Python——【USACO 3.3.5】——A Game
- 我的Laravel学习之路之migration Laravel自带命令行数据库创建和管理工具
- session和cookie的区别和联系
- 软键盘弹出/缩回事件监听
- Android性能优化之利用强大的LeakCanary检测内存泄漏及解决办法
- 继承(基础)
- easyui中datagrid的destroyUrl方法源码的修改从而使传送的数据是对象
- java源码中的生词摘录成有道词典单词本
- UML类图与类的关系详解