URAL 2000. Grand Theft Array V(贪心啊)

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=2000

2000. Grand Theft Array V

Time limit: 0.5 second

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

input output
10
1 2 3 4 5 6 7 8 9 0
4 8
21 24

Problem Author: Ilya Kuchumov. (Prepared by Kirill Devyatkin)

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;
}
/*
5
1 2 3 4 5
2 3
5
1 2 3 4 5
2 4
*/
时间: 2024-11-03 21:36:55

URAL 2000. Grand Theft Array V(贪心啊)的相关文章

Grand Theft Auto V (侠盗列车手5)图形研究

原文地址:http://www.adriancourreges.com/blog/2015/11/02/gta-v-graphics-study/ 原文的简介: GTA(侠盗猎车)系列自从1997年首部发售以来有了很大的进步,两年前,Rockstar发布的GTAV获得了成功,首日1100万套的销量打破了7项吉尼斯世界记录. 在PS3上游玩时,游戏的完成水准和技术质量给我留下了深刻印象.加载屏幕是最影响体验的:而在GTA中你可以游戏几个小时,在一个巨大的开放世界中驾车数百公里,而没有任何的中断.考

Codeforces 442C Artem and Array(stack+贪心)

题目连接:Codeforces 442C Artem and Array 题目大意:给出一个数组,每次删除一个数,删除一个数的得分为两边数的最小值,如果左右有一边不存在则算作0分.问最大得分是多少. 解题思路:首先将连续的a,b,c,a > b && c > b的情况将c掉,获得min(a,b)分,这样处理后数组变成一个递増再递减的序列,除了最大和第二大的取不到,其他数字均可以得分. 样例:4 10 2 2 8 #include <cstdio> #include

URAL 1025. Democracy in Danger (贪心)

1025. Democracy in Danger Time limit: 1.0 second Memory limit: 64 MB Background In one of the countries of Caribbean basin all decisions were accepted by the simple majority of votes at the general meeting of citizens (fortunately, there were no lots

URAL 2019 Pair: normal and paranormal (贪心) -GDUT联合第七场

比赛题目链接 题意:有n个人每人拿着一把枪想要杀死n个怪兽,大写字母代表人,小写字母代表怪兽.A只能杀死a,B只能杀死b,如题目中的图所示,枪的弹道不能交叉.人和怪兽的编号分别是1到n,问是否存在能全部杀死的情况,如果存在则输出编号1到n的每个人杀死的怪兽的编号,如果不能输出"Impossible". 题解:贪心,用递归实现,判断相邻的是否能构成一对,优先构成相邻的,如果不能就递归到前面看是否能构成一对即可. #include<cstdio> #include<cst

Codeforces 402D Upgrading Array:贪心 + 数学

题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中p是s的最小质因子: f(1) = 0 f(s) = f(s/p) + 1 (p不是坏质数) f(s) = f(s/p) - 1 (p是坏质数) 你可以任意次数地进行操作:给a[1 to i]的每个数都除以gcd(a[1 to i]). 问你 ∑ f(a[i)最大为多少. 题解: 函数f(s)的实际

Atcoder Grand Contest 037C(贪心,优先队列,思维)

#define HAVE_STRUCT_TIMESPEC//编译器中time.h和phread.h头文件中timespec结构体重名,故加此行#include<bits/stdc++.h>using namespace std;int a[200007],b[2000007];priority_queue<pair<int,int> >q;int n;int mi(int x){ return x==1?n:x-1;}int pl(int x){ return x==n

URAL 1787 Turn for MEGA (贪心 + 模拟)

Turn for MEGA Time limit: 1.0 second Memory limit: 64 MB A traffic light at the turn for the "MEGA" shopping center from the Novomoskovskiy highway works in such a way that k cars are able to take a turn in one minute. At weekends all the reside

Lessons Learned from Developing a Data Product

Lessons Learned from Developing a Data Product For an assignment I was asked to develop a visual ‘data product’ that informed decisions on video game ratings taking as an indicator their ranking on the MetaCritic site. I decided to use RStudio’s Shin

Steam 导入已下载好的游戏

转自:http://game.ali213.net/thread-5693230-1-1.html 本人已经完美解决了 办法如下:零售版导入方法1:在STEAM先不要有任何GTAV的下载进程,如果有请删除.2:然后进入Steam\steamapps\common,如果没有的话可以自行新建.3:将游戏COPY进去就可以了.游戏文件夹的名字一定要是Grand Theft Auto V4:进入Steam,点下载.然后Steam就会发现GTAV的游戏缓存,然后等待验证结束.5:验证结束后,会进入下载游戏