题目描述

Alice and Bob are always playing game! The game today is about taking out stone from the stone piles in turn.
There are n piles of stones, and the i-th pile contains A[i] stones.
As the number of stones in each pile differs from its neighbor’s, they determine to take out exactly one stone from one of them in one turn without breaking that property. Alice goes first.
The player who cannot take stone will lose the game.
Now you have to determine the winner given n numbers representing the piles, if they both play optimally.
You should notice that even a pile of 0 stone is still regarded as a pile!

输入

The first line of input file contains an integer T (1≤T≤100), describing the number of test cases.
Then there are 2×T lines, with every two lines representing a test case.
The first line of each test case contains only one integer n (1≤n≤105) as described above.
The second line of that contains exactly n numbers, representing the number of stone(s) in a pile in order.
All these numbers are ranging in [0,109].
It is guaranteed that the sum of n in all cases does not exceed 106.

输出

You should output exactly T lines.
For each test case, print Case d: (d represents the order of the test case) first, then print the name of winner, Alice or Bob .

样例输入
复制样例数据

2
2
1 3
3
1 3 1
样例输出

Case 1: Alice
Case 2: Bob

提示

Sample 1:
There is a possible stone-taking sequence: (1,3)-> (1,2)-> (0,2)-> (0,1)
Here is an invalid sequence: (1,3)-> (1,2)-> (1,1)-> (0,1). Though it has the same result as the first sequence, it breaks that property “the number of stones in each pile differs from its neighbor’s”.
思路来自于2018CCPC桂林站题解(D G H J L)

  题目大意:n堆石子,保证相邻两堆不等。A和B玩游戏,轮流从这n堆中,任意拿走一颗石子,但需要保证拿走第i堆的一颗石子后,第i堆的石子不能和他相邻堆相等。谁无法拿石子时,谁就输。问谁能赢?

  因为相邻位置的数目不能相同,如果对于两个位置x,y的石头有a[x]>a[y],那么一直有a[x]>a[y],因为每个只能取一个,多那个是不可能越过少那个的。所以整个取石头的过程中,序列的单调性是不变的,那么当不可以再取时,序列中的极小值处肯定取为0了,我们就可以从极小值处向两边的峰值扩展,逐渐递增。而当两个极小值的峰值相遇时,就说明这个位置的值大于它两边的值,根据前面的a[x]>a[y]是恒定不变的,那么这个位置的最后的值就应该为它两边更大的那个+1。处理完所有极小值之后,就得到了不能再取时的序列,它和原序列的差就是总共能取的石头数,如果是奇数那么是alice赢,反正bob。详情见代码。

 #include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=,inf=1e9+;
int a[N],b[N];
int main()
{
int t=,T,n;
scanf("%d",&T);
while(t<=T)
{
scanf("%d",&n);
ll sum=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
sum+=a[i];
b[i]=inf;
}
printf("Case %d: ",t++);
if(n==)//1的时候奇偶性特判
{
if(sum&)
printf("Alice\n");
else
printf("Bob\n");
continue;
}
a[]=a[n+]=inf;//两端也可能是极小值,在序列的两边增加个尽可能大的值进行处理
for(int i=;i<=n;i++)
if(a[i]<a[i-]&&a[i]<a[i+])//先找到极小值设为0
b[i]=;
for(int i=;i<=n;i++)
{
if(!b[i])
{ //从极小值向两边递增
for(int j=i+;j<=n&&a[j]>a[j-];j++)
b[j]=b[j-]+;
for(int j=i-;j>=&&a[j]>a[j+];j--)
if(a[j]>a[j-]&&a[j]>a[j+])//当两个极小值的峰值相遇
b[j]=max(b[j-],b[j+])+;
else
b[j]=b[j+]+;
}
}
for(int i=;i<=n;i++)
sum-=b[i];
if(sum&)
printf("Alice\n");
else
printf("Bob\n");
}
return ;
}

不够聪明怎么办

最新文章

  1. Hibernate的session一级缓存
  2. android之MP3播放器(1)
  3. Leetcode 之Validate Binary Search Tree(53)
  4. 序列的方法(str,list,tuple)
  5. 为什么Linux的fdisk分区时第一块磁盘分区的First Sector是2048?
  6. Tomcat server分端口部署web项目
  7. Math.sqrt
  8. redis研究记录
  9. 续x奇数倍(n+2*x)暴力算法是冠军的算法结合数量
  10. NodeJs+Express实现简单的Web增删改查
  11. Ansible Lookup
  12. 最简单易懂的webService客户端之soap+xml请求
  13. 阿里云centos下安装nginx、jdk、tomcat、绑定域名、解析域名
  14. 读取指定文件夹下的全部文件,可通过正则进行过滤,返回文件路径数组 -- 基于node的一个函数
  15. CSS(三)背景 list-style display visibility opacity vertical cursor
  16. vi/vim操作
  17. springboot实现简单的文件上传
  18. git教程:管理修改
  19. MySQL系列详解十:MySQL多源复制演示-技术流ken
  20. cas:覆盖安装

热门文章

  1. 树链剖分 树剖求lca 学习笔记
  2. 第九章 MIZ702 ZYNQ片上ADC的使用
  3. Devepxress xaf Dashboard中DetailView控件使其可编辑
  4. shell习题第18题:检查新文件
  5. Delphi编译器属性(特别修饰符Ref,Unsafe,Volatile,Weak)
  6. 核发电站 (dp前缀优化)
  7. Spring实战(五)Spring中条件化地创建bean
  8. luogu1005矩阵取数游戏题解--区间DP
  9. YoloV3 训练崩溃
  10. Oracle 调试存储过程