题目描述

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

不够聪明怎么办

2018CCPC桂林站JStone Game的更多相关文章

  1. 2018CCPC桂林站G Greatest Common Divisor

    题目描述 There is an array of length n, containing only positive numbers.Now you can add all numbers by ...

  2. 2018 CCPC 桂林站(upc复现赛)补题

    2018 CCPC 桂林站(upc复现赛)补题 G.Greatest Common Divisor(思维) 求相邻数的差值的gcd,对gcd分解素因子,对所有的素因子做一次遍历,找出最小答案. 几个样 ...

  3. 2018ccpc秦皇岛站后记

    总的来说这不是一场体验十分好的比赛. 定的宾馆有一点小,学校提供的伙食人太多了,不想排队,饭票又不能换香蕉,就没有吃. 到的第一天遇到了价格向上取整和到站不打发票的两个黑车司机,让我对这个地点好感大减 ...

  4. 2018CCPC秦皇岛站

    这次去秦皇岛,两个队都打铁回来,真的是蛮耻辱的 可以说是有史以来最差成绩了 其实网络赛就打的不好 两个名额一个是省赛分配的一个是排队排来的 去之前拉了几场之前的CCPC的比赛打 感觉打的都还不错的 热 ...

  5. 2018 CCPC 桂林站(upc复现赛)总结

    比赛一开始盯上了A题和G题,一个小时过去了还没有出题,心里有些乱.这时我看D题很多人过了,于是宝儿去看D题,说D题简单,转化成二进制暴力,于是就去做了.写的时候好像思路有点卡,WA了一发,后来马上发现 ...

  6. 牛客练习赛38 E 出题人的数组 2018ccpc桂林A题 贪心

    https://ac.nowcoder.com/acm/contest/358/E 题意: 出题人有两个数组,A,B,请你把两个数组归并起来使得cost=∑i∗ci 最小,归并要求原数组的数的顺序在新 ...

  7. 2018 桂林ccpc现场赛 总结

    Day 0 5个小时的火车,坐的昏昏欲睡.桂林站出来没有地铁,而是出租车排成长队依次上车,也算是某种意义上的地铁吧.到了酒店才发现学校那边又给我们换了,又拖着行李找新的酒店,途中路过一家餐馆,所有人都 ...

  8. CCPC2018 桂林 D "Bits Reverse"

    传送门 题目描述 Now given two integers x and y, you can reverse every consecutive three bits ,,) means chan ...

  9. 台州学院maximum cow训练记录

    前队名太过晦气,故启用最大牛 我们的组队大概就是18年初,组队阵容是17级生詹志龙.陶源和16级的黄睿博. 三人大学前均无接触过此类竞赛,队伍十分年轻.我可能是我们队最菜的,我只是知道的内容最多,靠我 ...

随机推荐

  1. 剑指offer14:输入一个链表,输出该链表中倒数第k个结点。

    1. 题目描述 输入一个链表,输出该链表中倒数第k个结点. 2. 思路和方法 可以用两个指针,一个指针遍历到第k个结点的时候,第二个指针再走到第一个节点,然后两个指针的距离始终保持k-1.这样,当第一 ...

  2. 关于centOS安装配置xampp那点事

    1.到官网下载centOS对应版本的xampp,应该是以tar.gz为后缀的 2.tar -zxf 下载的包 3.mv lampp /opt 4.service mysqld stop因xampp里自 ...

  3. 【搜索】n的约数

    题目链接:传送门 [题解]: 考察dfs和质因数分解,首先开一个prime数组. 参数解释: 1.当前值的大小.[利用题目的n来控制范围] 2.控制下界,每次都是以某一个质数开始搜索, pos 3.控 ...

  4. jquery tablesorter 动态加载数据时,排序。过滤失效解决方案

    解决方案:重置更新: $("table").trigger("update"); 1 官方 ajax表格数据添加实例: $(document).ready(fu ...

  5. 【Android】二、HelloWorld

    1. 按照该网址写HelloWorld 例子   http://www.runoob.com/android/android-hello-world-example.html 2.点击 make pr ...

  6. http GET 和 POST 请求的优缺点和误区

    (1)post更安全(不会作为url的一部分,不会被缓存.保存在服务器日志.以及浏览器浏览记录中) (2)post发送的数据更大(get有url长度限制) (3)post能发送更多的数据类型(get只 ...

  7. 有趣的"=="与"==="

    console.log([]==![]);//true //"=="会进行类型转换,转换成统一类型进行比较 // !符号优于==,[]boolean值为TRUE,所以![]就是FA ...

  8. requests模块高级操作之cookie

    一.cookie 存储在客户端的键值对,可以让服务端记录客户端相关状态. 如何处理cookie? 手动处理: 将抓包工具中的请求头信息中的cookie键值拷贝到header中 自动处理:session ...

  9. 【SpringBoot】Web开发

    一.简介 1.1 引入SpringBoot模块 1.2 SpringBoot对静态资源的映射规则 二.模版引擎 2.1 简介 2.2 引入thymeleaf 2.3 Thymeleaf使用 一.简介 ...

  10. mmap:内存映射文件

    介绍 建立一个文件的内存映射将使用操作系统虚拟内存来直接访问文件系统上的数据,而不是使用常规的I/O函数访问数据. 内存映射通常可以提高I/O性能,因为使用内存映射时,不需要对每一个访问都建立一个单独 ...