问题 G: ABS

时间限制: 1 Sec  内存限制: 128 MB
提交: 537  解决: 186
[提交] [状态] [讨论版] [命题人:admin]

题目描述

We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is ai.
Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:
Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.
The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.
X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

Constraints
All input values are integers.
1≤N≤2000
1≤Z,W,ai≤109

输入

Input is given from Standard Input in the following format:
N Z W
a1 a2 … aN

输出

Print the score.

样例输入

3 100 100
10 1000 100

样例输出

900

提示

If X draws two cards first, Y will draw the last card, and the score will be |1000−100|=900.


  博弈问题。

  大概题意:

  X,Y两个人,手中各有一张牌,牌上的数字大小分别是Z,W。此时桌子上有N张牌,X、Y两个人一前一后从桌子上拿任意多的牌。

  每次拿到几张牌后,把手头原有的牌扔掉,只保留刚刚拿起的这些牌里最后的一张。

  一直到拿到桌子上没有牌之后,比较X、Y两个人手中牌的差。

  X的目的是让结果最大化,Y的目的是让结果最小化 。

  

  这个题做的时候没有想到什么办法,因为桌子上的牌的数值是不确定的,没有办法根据这个直接判断,所以当时干脆让X先拿的时候拿到第 n-1 个或者第 n 个,然后进行对比,基本就是模拟了一下样例的过程。

  然后该坐等WA了(稳如老狗)

  哈?竟然过了emmmmm。。。好吧。。。。

  上代码(已AC)

 #include<iostream>
#include<cstdlib>
#include<math.h>
using namespace std; int main(){
int n, z, w, a[];
cin >> n >> z >> w;
for(int i=;i<=n;i++) cin >> a[i];
if(n==) {
cout << llabs(a[n]-w);
}
else{
cout << max(llabs(a[n]- a[n-]), llabs(a[n] - w));
}
return ;
}

  

UPC:ABS的更多相关文章

  1. python常用函数之--求绝对值函数:abs(x)

    python中的求绝对值函数:abs(X) 1. 参数 x 可以是整形也可以是复数,假如是复数的话,就求复数的模. >>> # 整形数字 ... >>> a = 1 ...

  2. python函数回顾:abs()

    函数:abs() 官方英文文档解释 abs(x) Return the absolute value of a number. The argument may be a plain or long ...

  3. 模板:abs用法

    c语言书本上说,数学函数除了求整数的绝对值函数abs()之外<abs() 定义在stdlib.h中>,其余的函数都在头文件 math.h 中定义,包括对浮点数求绝对值的函数fabs().c ...

  4. Python标准库:内置函数abs(x)

    返回数字的绝对值. 參数能够是整数或浮点数.假设參数是复数,则返回复数的模. 因此abs()函数的注意点就是复数的不一样计算方式. 样例: #正整数 print('abs(1):', abs(1)) ...

  5. Delphi 数学函数:常用的几个数学函数(Power、Abs、Int、Trunc、Round、Frac、sqr、sqrt)

    Delphi 常用的几个数学函数 1 Power函数,求次方 定义:function Power(X,Y): (Same type as parameter); 说明:X可以是整型,也可以是实型:返回 ...

  6. 跟着老男孩教育学Python开发【第二篇】:Python基本数据类型

    运算符 设定:a=10,b=20 . 算数运算 2.比较运算 3.赋值运算 4.逻辑运算 5.成员运算 基本数据类型 1.数字 int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**3 ...

  7. 转载:SqlServer数据库性能优化详解

    本文转载自:http://blog.csdn.net/andylaudotnet/article/details/1763573 性能调节的目的是通过将网络流通.磁盘 I/O 和 CPU 时间减到最小 ...

  8. 汽车ABS系统-第一周作业

    ABS系统也成防抱死系统(Anti-lock Braking System),由罗伯特·博世有限公司所开发的一种在摩托车和汽车中使用,它会根据各车轮角速度信号,计算得到车速.车轮角减速度.车轮滑移率: ...

  9. GJM :Sql 各种语句 以及函数 [转载]

    版权声明:本文原创发表于 [请点击连接前往] ,未经作者同意必须保留此段声明!如有侵权请联系我删帖处理! 1.更改数据库的名称 2.表中有数据的情况下再添加列.删除列 3.在SQLServer 中各种 ...

随机推荐

  1. iOS开发只简单动画实现

    1.动画旋转: [UIViewbeginAnimations:@"View Flip"context:nil]; //声明,@"XX"为标题, [UIViews ...

  2. Unity Shader Graph 小功能实现(一)边缘发光

    在Unity 2018.2 版本正式启用了高清渲染管线,shader可视化编程. 现在我们就尝尝鲜,来实现了个物体边缘发光的shader效果. 准备 点击Windos->Package Mang ...

  3. RF无线射频电路设计干货分享

    1.概述:射频(RF)PCB设计,在目前公开出版的理论上具有很多不确定性,常被形容为一种“黑色艺术”.通常情况下,对于微波以下频段的电路(包括低频和低频数字电路),在全面掌握各类设计原则前提下的仔细规 ...

  4. git cannot lock ref

    参考博客:https://blog.csdn.net/lindexi_gd/article/details/79213042 错误原文: cannot lock ref ‘refs/remotes/o ...

  5. python爬虫实践(一)

    最近在学习爬虫,学完后想实践一下,所以现在准备爬取校花网的一部分图片 第一步,导入需要的库 from urllib import request #用于处理request请求和获得响应 from ur ...

  6. Js 运行机制和Event Loop

    一.为什么JavaScript是单线程? JavaScript语言的一大特点就是单线程,也就是说,同一个时间只能做一件事.那么,为什么JavaScript不能有多个线程呢?这样能提高效率啊. Java ...

  7. TCPDF解决保存中文文件名的方法

    PHP使用TCPDF生成PDF文件时,如果文件名是中文会被直接过滤掉,以下是TCPDF不能保存中文文件名的解决方法: 打开tcpdf.php文件,找到output函数,大约在8467行 或(7554) ...

  8. CSS面试细节整理(二)

    5.css盒模型: CSS 框模型 (Box Model) 规定了元素框处理元素内容.内边距.边框 和 外边距 的方式

  9. java 的基本数据类型及转换

    数据类型精度: byte 8 位short 16 位int 32 位long 64 位float 32 位double 64 位char 16 位 boolean 占几位要看 jvm 的具体实现, 虽 ...

  10. ABP入门系列(1)——通过模板创建MAP版本项目

    ABP入门系列目录--学习Abp框架之实操演练 一.从官网创建模板项目 进入官网下载模板项目 依次按下图选择: 输入验证码开始下载 下载提示: 二.启动项目 使用VS2015打开项目,还原Nuget包 ...