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(…

Android中写文本文件的方法

下面是我在Android开发中&#xff0c;一个写文本文件的方法&#xff0c;代码如下&#xff1a; //将字符串写入到文本文件中 public static void WriteTxtFile(String strcontent,String strFilePath) { //每次写入时&#xff0c;都换行写 String strConten…

前端笔记-jquery

jquery简介 兼容性强,轻量级库,js的框架,国外的大神写好我们只要调用就好了,jquery可以把js写的更加简单 jquery使用 <script srcjquery-x.x.x.js></script> 引入文件就行了 jquery语法 $(selector).action() jquery选择器 1.基本选择器 $("*") $(&quo…

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…

面试官: 用css实现android系统的loading动画

源码: github.com/any86/any-u… ios/android web常用的loading图标有2种, 一种是ios的"菊花", 一种是android的"环". 今天我们用svg实现android的"环"动画, 下节课实现ios的"菊花". 注意: gif帧数少的原因, 实际动画效果是很平滑的.d…

2018-06-29 西游记主题Python入门示例尝试-数据结构 5.1-5.1.2

(见前: 中文代码示例视频演示Python入门第五章 数据结构 仍然基于官方文档, 欢迎建议(尤其是如何取材). 5. Data Structures - More on Lists 列表详述 >>> 人物 [佛, 妖, 凡人, 菩萨, 妖, 凡人] >>> 人物.count(妖) 2 >>> 人物.count(圣人) 0 >…

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…

C#循环给多个控件赋值

需要给 多个 文本框重新赋值 1 textBox1.Text"ss"; 2 3 textBox2.Text"ss"; 4 5 textBox999.Text"ss"; 6 7 textBox99999.Text"ss"; 这样太麻烦&#xff0c;控件过多不方便写 通过遍历 一次性赋值&#xff0c;再多也不怕了 将所有T…

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

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

关于REST API设计的一些小经验

版权声明&#xff1a;转载时请以超链接形式标明文章原始出处和作者信息及本声明http://phoenixtoday.blogbus.com/logs/45855234.html 最近小组里有一些关于REST API设计的讨论&#xff0c;有些收获&#xff0c;打算在这里写一下。通常来讲设计第一个版本的REST API并不难&…

1037 在霍格沃茨找零钱

题目传送门&#xff1a;https://pintia.cn/problem-sets/994805260223102976/problems/994805284923359232 题解&#xff1a; #include<iostream> using namespace std;int main() {int Galleon1, Sickle1, Knut1, Galleon2, Sickle2, Knut2;char c;cin >> Galleon…

我对创业和管理的一些看法

创业&#xff0c;对于刚工作的人&#xff0c;会比较兴奋&#xff0c;因为创业充满想象力&#xff1b;对于工作几年的人&#xff0c;会比较向往&#xff0c;因为压抑得太久。其实&#xff0c;创业和就业一样&#xff0c;只是实现自己人生价值的两种方式&#xff0c;关键是心态问…

关于Anaconda的环境和包管理

Anaconda相对于原生python解释器具有更好的包管理功能&#xff0c;它有一个env文件夹&#xff0c;里面包含所要管理的所有环境&#xff1b;日常操作时我们可能会使用pytorch、Tensorflow等多个环境&#xff0c;由于每个环境对Python的包的兼容性都不一样&#xff0c;所以我们可…

WCF basicHttpBinding之Message Security Mode

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

战略游戏

题目描述 Bob喜欢玩电脑游戏&#xff0c;特别是战略游戏。但是他经常无法找到快速玩过游戏的办法。现在他有个问题。 他要建立一个古城堡&#xff0c;城堡中的路形成一棵树。他要在这棵树的结点上放置最少数目的士兵&#xff0c;使得这些士兵能了望到所有的路。 注意&#xff0…

Vue语法学习第三课——计算属性

模板内的表达式非常便利&#xff0c;但是设计它们的初衷是用于简单运算的。在模板中放入太多的逻辑会让模板过重且难以维护。对于任何复杂逻辑&#xff0c;都应当使用计算属性。 <div id"example"><p>original message : "{{message}}"</p&…

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

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

neo4j删除所有节点

MATCH (n)OPTIONAL MATCH (n)-[r]-()DELETE n,r转载于:https://www.cnblogs.com/luoganttcc/p/10525189.html

Hadoop RPC实例

本文发表于本人博客。 上次写了个hadoop伪分布环境搭建的笔记了&#xff0c;今天来说下hadoop分布式构建的基础RPC&#xff0c;这个RPC在提交Job任务的时候底层就是创建了RPC来实现远程过程调用服务端。 我们首先可以通过Job的waitForCompletion(boolean verbose)方法来跟踪代码…