问题 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 ;
}

  

最新文章

  1. SQL Server-聚焦查询计划Stream Aggregate VS Hash Match Aggregate(二十)
  2. Python 类变量和成员变量
  3. OpenMP求完数
  4. Learning Scrapy笔记(一)- Scrapy简单介绍
  5. OpenCV中的常用函数
  6. 设计模式------PROTOTYPE(原型),TEMPLATE(模板)
  7. Java实现SSO
  8. Codeforces 190E - Counter Attack
  9. gir配置
  10. js中&amp;&amp; 和 ||
  11. Nyoj 城市平乱(图论)
  12. Visual Studio 2014
  13. 多标记学习--Learning from Multi-Label Data
  14. C++------------typedef 函数指针类型定义
  15. SQL SERVER 报:由于数据移动,未能继续以 NOLOCK 方式扫描错误的解决办法。
  16. windows 安装Mysql压缩包
  17. SDK,API概念
  18. WPF软件开发系统之六——药品管理查询系统
  19. hihocoder1524
  20. zookeeper基本概念

热门文章

  1. 《Java项目中classpath路径详解》
  2. 学习随笔:Django 补充及常见Web攻击 和 ueditor
  3. DCDC设计指南二
  4. Y1吐槽002 情绪
  5. wpf 的各个template
  6. Golang的模块管理Module
  7. java常用框架
  8. [LeetCode] Bus Routes 公交线路
  9. 第一个servlet程序
  10. 教你 Debug 的正确姿势——记一次 CoreMotion 的 Crash