Georgia and Bob POJ - 1704 阶梯Nim

$ \color{#0066ff}{ 题目描述 }$

Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ..., and place N chessmen on different grids, as shown in the following figure for example: img Georgia and Bob move the chessmen in turn. Every time a player will choose a chessman, and move it to the left without going over any other chessmen or across the left edge. The player can freely choose number of steps the chessman moves, with the constraint that the chessman must be moved at least ONE step and one grid can at most contains ONE single chessman. The player who cannot make a move loses the game. Georgia always plays first since "Lady first". Suppose that Georgia and Bob both do their best in the game, i.e., if one of them knows a way to win the game, he or she will be able to carry it out. Given the initial positions of the n chessmen, can you predict who will finally win the game?

\(\color{#0066ff}{输入格式}\)

The first line of the input contains a single integer T (1 <= T <=20), the number of test cases. Then T cases follow. Each test case contains two lines. The first line consists of one integer N (1 <= N <= 1000), indicating the number of chessmen. The second line contains N different integers P1, P2 ... Pn (1 <= Pi <= 10000), which are the initial positions of the n chessmen.

\(\color{#0066ff}{输出格式}\)

For each test case, prints a single line, "Georgia will win", if Georgiawill win the game; "Bob will win", if Bob will win the game; otherwise 'Not sure'.

\(\color{#0066ff}{输入样例}\)

2
3
1 2 3
8
1 5 6 7 9 12 14 17

\(\color{#0066ff}{输出样例}\)

Bob will win
Georgia will win

\(\color{#0066ff}{数据范围与提示}\)

none

\(\color{#0066ff}{题解}\)

移动一个棋子,与左边的距离减小,与右边的距离增大

可以抽象成几堆石子,从一堆拿到另一堆,这就是阶梯NIM了

#include <cctype>
#include <cstdio>
#include <algorithm>#define LL long long
LL in() {char ch; LL x = 0, f = 1;while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));return x * f;
}
const int maxn = 2050;
int a[maxn], b[maxn];
int main() {for(int T = in(); T --> 0;) {int n = in();for(int i = 1; i <= n; i++) a[i] = in();std::sort(a + 1, a + n + 1);int ans = 0;for(int i = n; i >= 1; i -= 2)ans = ans ^ (a[i] - a[i - 1] - 1) ;     puts(!ans? "Bob will win" : "Georgia will win");}return 0;
}

转载于:https://www.cnblogs.com/olinr/p/10491697.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/248400.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Tomcat总结

Tomcat调优原理&#xff1a; 1、增加最大连接数&#xff08;增大值避免队列请求过多&#xff0c;导致响应缓慢&#xff09; 2、调整工作模式 Bio(BlockingI/O)&#xff1a;默认工作模式&#xff0c;阻塞式I/O操作&#xff0c;没有任何优化技术处理&#xff0c;性能比较低。Nio(…

JVM的监控工具之jstack

参考博客&#xff1a;https://www.jianshu.com/p/213710fb9e40 jstack&#xff08;Stack Trace for Java&#xff09;命令用于生成虚拟机当前时刻的线程快照&#xff08;一般称为threaddump或者javacore文件&#xff09;。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈…

liunx驱动----异步通知

查询&#xff1a;消耗资源 中断&#xff1a;read 一直要去读poll &#xff1a;指定起始时间异步通知signal 测试程序include <stdio.h> include <signal.h>void my_signal(int signum) {static unsigned int cnt;printf("signum %d, %d timer\n",signum…

Niginx 集群负载均衡策略

Niginx 集群负载均衡策略 所需物料 1.Nginx服务 步骤略 本人 nginx version: nginx/1.16.0 2.Java Servlet 测试项目 新建java web 项目&#xff0c;项目名称为&#xff1a;tt import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annot…

记号一次更换IBM X3650M4主板后RAID无法启动的解决

https://wenku.baidu.com/view/9d503ef367ec102de2bd89d7.html 强烈感谢上面分享文档的大侠&#xff01;&#xff01; 1、更换主板后&#xff0c;linux系统&#xff0c;无法加载引导。需要设置主板的启动项 2、选择boot manager&#xff0c;进到下面的画面 3、选择add boot opt…

WCF basicHttpBinding之Message Security Mode

原创地址&#xff1a;http://www.cnblogs.com/jfzhu/p/4067873.html 转载请注明出处 前面的文章《WCF Security基本概念》介绍了WCF的security mode&#xff0c;简单说Transport是transport级别上的加密&am…

云计算学习资料分享:type查看命令

type 查看命令类型&#xff0c;例如该命令是alias&#xff0c;还是内置命令&#xff0c;还是某个文件&#xff0c;还是关键字 哪种神仙&#xff1a;天上还是地上&#xff0c;还是水里游的 [roottianyun ~]# type ll ll is aliased to ls -l --colorauto [roottianyun ~]# type …

关于83版射雕英雄传

今天无意中看到网上一群人关于83版射雕的一些争论.或许一些现在的年轻人不喜欢83版射雕,说那太老土了,但想想那个时代的条件,能拍出这样的片子,是非常不错的,而且我觉得83版射雕也是最忠于原著的,跟后来的翻版比较,虽然从画面效果,人物服装方面存在差距,但这都是由于历史原因和…

电子书下载:Programming Microsoft LINQ in Microsoft .NET Framework 4

Book DescriptionDig into LINQ — and transform the way you work with data. With LINQ, you can query data from a variety of sources — including databases, objects, and XML files — directly from Microsoft Visual Basic or C#. Guided by data-access experts w…

原型模式 —— Java的赋值、浅克隆和深度克隆的区别

赋值 直接 &#xff0c;克隆 clone 假如说你想复制一个简单变量。很简单&#xff1a; int a 5; int b a; b 6;这样 a 5, b 6 不仅仅是int类型&#xff0c;其它七种原始数据类型(boolean,char,byte,short,float,double.long)同样适用于该类情况。 但是如果你复制的是一个…

[scrum]2011/9/24-----第四天

scrum 总结&#xff1a; Team member Yesterday’s Work Today’s Work Issue R X Task201&#xff1a;Active Agenda Page的重写&#xff0c;界面设置 Task201&#xff1a;Active Agenda Page 界面的美化&#xff0c;收缩折叠&#xff0c;并添加一些动画效果 Task 243:…

ARM学习笔记7——乘法指令

ARM乘法指令完成两个数据的乘法&#xff0c;两个32位二进制数相乘的结果是64位的4积。 其中&#xff1a; 1、“RadHi:RdLo”是由RdHi(最高有效32位)和RdLo(最低有效32位)链接形成的64位数&#xff0c;“[31:0]”只选取结果的最低有效32位 2、简单的赋值由“&#xff1a;”表示…

固态硬盘Ghost安装Windows 10无法引导的问题

机器配置如下&#xff1a; 电脑型号 技嘉 B360M POWER 台式电脑操作系统 Windows 10 64位 ( DirectX 12 )处理器 英特尔 Core i7-8700 3.20GHz 六核主板 技嘉 B360M POWER ( 英特尔 PCI 标准主机 CPU 桥 - CannonLake - A3…

[转]矩阵分解在推荐系统中的应用

矩阵分解是最近几年比较火的算法&#xff0c;经过kddcup和netflix比赛的多人多次检验&#xff0c;矩阵分解可以带来更好的结果&#xff0c;而且可以充分地考虑各种因素的影响&#xff0c;有非常好的扩展性&#xff0c;因为要考虑多种因素的综合作用&#xff0c;往往需要构造cos…

iPhone 系统刷机

1. 下载好固件(爱思 或者 pp助手) e.g. http://jailbreak.25pp.com/gujian/ 2. 将电脑与手机连接上&#xff0c;弹出iTunes软件即可 3. 长按手机电源键 关闭手机 4. 按住电源健&#xff0c;出现屏幕亮出现苹果标志后再按住Home健 5. 屏幕黑屏时松开电源健&#xff0c;继续按照H…

Java内存模型深度解析:总结

处理器内存模型 顺序一致性内存模型是一个理论参考模型&#xff0c;JMM和处理器内存模型在设计时通常会把顺序一致性内存模型作为参照。JMM和处理器内存模型在设计时会对顺序一致性模型做一些放松&#xff0c;因为如果完全按照顺序一致性模型来实现处理器和JMM&#xff0c;那么…

sourcetree,创建工作流报错:Fatal: Not a gitflow-enabled repo yet. Please run 'git flow init' first.-》解决办法...

1、打开项目下.git/config文件&#xff0c;或者如下图操作&#xff1a; 2、打开config文件以后&#xff0c;删除所有 [gitflow *条目并保存文件 3、关闭并重新打开sourcetree 4、仓库-》Git 工作流-》初始化仓库即可转载于:https://www.cnblogs.com/yxfeng/p/10536955.html

关于a标签的href属性的注意事项

今天在做一个lightbox效果的时候出现了一个问题。 当往下滚动再点击按钮出现lightbox的时候&#xff0c;lightbox的遮罩层不能铺满&#xff08;即滚动高度处不能铺上&#xff09;&#xff0c;如下图所示。原因是提交按钮使用的是a标签&#xff0c;当给a标签写上href属性的时候&…

在mac上安装gitlab

参考链接&#xff1a; https://www.cnblogs.com/floodwater/p/10138265.html 注意事项&#xff1a; 在安装gitlab-ce时&#xff0c;配置hostname域名后&#xff0c;通过域名访问gitlab时&#xff0c;需要配置本机hosts文件&#xff0c;不然不能访问 本地hosts文件中配置后 就可…

d3.js 入门指南

说到数据可视化&#xff0c;我们会行到很多优秀的框架&#xff0c;像echarts、highcharts&#xff0c;这些框架很优雅&#xff0c;健壮&#xff0c;能满足我们对可视化的大部分需求&#xff0c;但是缺点也很明显&#xff0c;就是这些框架几乎是不可定制化的&#xff0c;当遇到特…