问题 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. 起泡排序(Bubble sort)

    局部有序和整体有序 在由一组整数组成的序列A[0, n-1]中,满足 $ A[i - 1] \leq A[i] $ 的相邻元素称为顺序的:否则是逆序的. 扫描交换 由有序序列的特征,我们可以通过不断改 ...

  2. Java 多文件压缩成一个文件工具类

    简单修改来自博客园勇闯天涯zfc的博客 一.内容 ①使用 Java 将多个文件打包压缩成一个压缩文件: ②主要使用 java.io 下的类 二.源代码:ZIPUtil .java import jav ...

  3. python函数用法

    一.定义函数 形参:函数完成一项工作所需要的信息,在函数定义时完成 实参:调用函数时传递给函数的信息 二.传递实参 1.位置实参:每个实参都关联到函数定义中的一个形参 示例: def describe ...

  4. php操作数组函数

    整理了一份PHP开发中数组操作大全,包含有数组操作的基本函数.数组的分段和填充.数组与栈.数组与列队.回调函数.排序.计算.其他的数组函数等. 一.数组操作的基本函数 数组的键名和值 array_va ...

  5. tyflow车撞墙测试

  6. LIS的优化算法O(n log n)

    LIS的nlogn的优化:LIS的优化说白了其实是贪心算法,比如说让你求一个最长上升子序列把,一起走一遍. 比如说(4, 2, 3, 1, 2,3,5)这个序列,求他的最长上升子序列,那么来看,如果求 ...

  7. 二分- Count on Canton

    题目: 代码: 是一个蛇形数列,把题目上的那组数倒过来看成一个正三角形. 第一行有1个数,1-2行有三个数,1-4行有6个数,1-4行有10个数,1-5行有15个数..... 现在要求第n个数是多少, ...

  8. Spring源码工程导入Eclsipse缺少两个jar文件

    按照<Spring源码深度解析>所述,使用gradle cleanidea eclipse将Spring源码转为eclipse工程后,导入eclipse,最后发现还是缺少spring-cg ...

  9. 深入分析volatile的实现原理

    synchronized是一个重量级的锁,虽然JVM对它做了很多优化,而下面介绍的volatile则是轻量级的synchronized.如果一个变量使用volatile,则它比使用synchroniz ...

  10. 基本类型数据转换(int,char,byte)

    public class DataUtil { public static void main(String[] args) { int a = 8; int value = charToInt(by ...