URAL 2000. Grand Theft Array V(贪心啊)
来源:互联网 发布:组三组六计划软件 编辑:程序博客网 时间:2024/04/29 07:25
题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2000
2000. Grand Theft Array V
Time limit: 0.5 second
Memory limit: 64 MB
Memory limit: 64 MB
A long anticipated game called Grand Theft Array V is about to appear in shops! What, haven’t you heard of it? Then we must tell you all about it!
The gameplay in GTA V takes place on a one-dimensional array of integers. The game has two players, each player has his own specified starting position. Players move in turns. During each turn a player takes a number written in his current cell, then writes a zero in it and moves to the left or right adjacent cell. Naturally, the player cannot move beyond the boundaries of the array. At some moment of time two players can be located in the same cell. A player’s score is the sum of all numbers he earns during the game. The game ends when zeroes are written in all cells of the array.
Now please calculate the maximum number of points the first and the second player can get (the first player moves first, naturally), if they play optimally well, that is, if they try to maximize their score and if there are multiple variants of maximizing one’s own score, they try to minimize the opponent’s score.
Input
The first line contains an integer n that is the size of array (10 ≤ n ≤ 105). The second line contains n integers representing the initial array. All elements of the array are non-negative and do not exceed 10 000. The third line contains two integers that are the starting positions of the first and the second player, correspondingly. The cells of the array are indexed starting from one.
Output
Output the score of the first and the second player correspondingly if both play optimally well.
Sample
101 2 3 4 5 6 7 8 9 04 8
21 24
Problem Author: Ilya Kuchumov. (Prepared by Kirill Devyatkin)
Problem Source: Ural Regional School Programming Contest 2013
Problem Source: Ural Regional School Programming Contest 2013
题意:
两个人从给出的两个点出发,每次只能向左或向右移一步!每个人所得分数就是移到的单元格的分数,然后把所在单元格的分数设置为零!
求两个人分别能得到的最大分数!
PS:
贪心原则!最开始一定是先向对方所在的位置移动!移动到两个人初始位置距离的一半的时候在往回走! 这样对方永远不可能追上你!
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){ int n; int a[100047]; while(~scanf("%d",&n)) { int sum = 0; for(int i = 1; i <= n; i++) { scanf("%d",&a[i]); sum += a[i]; } int p1, p2; scanf("%d%d",&p1,&p2); int sum1 = 0, sum2 = 0; int ans = 0; if(p1 > p2) { int tt = (p1-p2)/2;// for(int i = 1; i <= p2+tt; i++)// {// sum2 += a[i];// } for(int i = p1-tt; i <= n; i++) { sum1 += a[i]; } ans = sum1;// ans = max(sum1, sum2); } else if(p1 == p2) { for(int i = 1; i <= p1; i++) { sum1 += a[i]; } for(int i = p2; i <= n; i++) { sum2 += a[i]; } ans = max(sum1, sum2); } else if(p1 < p2) { int tt = (p2-p1)/2; for(int i = 1; i <= p1+tt; i++) { sum1 += a[i]; }// for(int i = p2-tt+1; i <= n; i++)// {// sum2 += a[i];// }// ans = max(sum1, sum2); ans = sum1; } printf("%d %d\n",ans,sum-ans); } return 0;}/*51 2 3 4 52 351 2 3 4 52 4*/
1 0
- URAL 2000. Grand Theft Array V(贪心啊)
- URAL 2000 Grand Theft Array V 贪心
- timus 2000. Grand Theft Array V
- URAL 1735 Theft of the Century
- URAL 1820 Ural Steaks (贪心)
- URAL 2041 Nanomatryoshkas(贪心)
- UVA 10249 - The Grand Dinner(网络流 or 贪心)
- XVII Open Cup named after E.V. Pankratiev. Eastern Grand Prix. Problem F. Buddy Numbers 贪心、数论、构造
- URAL 1964 - Chinese Dialects(贪心)
- URAL 1203 Scientific Conference(贪心 || DP)
- Ural 1303 Minimal Coverage(贪心)
- URAL 2021 Scarily interesting!(贪心)
- URAL 1876. Centipede's Morning (贪心)
- URAL 1025. Democracy in Danger (贪心)
- Ural 1303 Minimal Coverage(贪心)
- ural 1820. Ural Steaks 贪心
- Leetcode330 - Patching Array(贪心)
- 330. Patching Array (贪心)
- 复杂数据类型——数组
- 我所遇到的GitLab 502问题的解决
- WCF HttpBinding 安全解析 (5)Basic验证(IIS宿主)
- 刮鸥技司止遗尾的氨链仕偎玫蚕挠
- android:nextFocus 属性介绍
- URAL 2000. Grand Theft Array V(贪心啊)
- 《Linux内核完全注释》 第2章 内核体系结构
- 计算机网络复习:主题1 Internet是如何组织其连接结构的
- 求解无向图的割点和桥
- WCF BasicHttpBinding 安全解析(6)Digest验证(IIS宿主)
- Java—传统定时器的简单使用
- mysql存储过程之事物管理
- POJ3592 Instantaneous Transference【强连通分量】【最长路】
- WS BasicHttpBinding 安全解析(7)Certificate验证(IIS宿主)