首页 技术 正文
技术 2022年11月8日
0 收藏 323 点赞 1,989 浏览 1849 个字

A Simple Nim

Problem Description Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed).To make the game more interesting,players can separate one heap into three smaller heaps(no empty heaps)instead of the picking operation.Please find out which player will win the game if each of them never make mistakes. Input Intput contains multiple test cases. The first line is an integer 1≤T≤100, the number of test cases. Each case begins with an integer n, indicating the number of the heaps, the next line contains N integers s[0],s[1],….,s[n−1], representing heaps with s[0],s[1],…,s[n−1] objects respectively.(1≤n≤106,1≤s[i]≤109) Output For each test case,output a line whick contains either”First player wins.”or”Second player wins”. Sample Input 2
2
4 4
3
1 2 4 Sample Output Second player wins.
First player wins. 题意:  给你n堆糖果  A,B两个人可以像nim游戏那样,在一堆中取任意个糖果  但是此题新增了, 玩家可以将一堆糖果分成三个非空堆,并且不取  最后取完的胜利;题解:  像这种暴力求SG函数会超时的  咋们就打表找规律  打表程序已给出,规律你就自己找吧

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define ls i<<1
#define rs ls | 1
#define mid ((ll+rr)>>1)
#define pii pair<int,int>
#define MP make_pair
typedef long long LL;
const long long INF = 1e18+1LL;
const double Pi = acos(-1.0);
const int N = 5e5+, M = 2e5+, mod = 1e9+, inf = 2e9;int sg[N],vis[N];
int main() {
/*sg[0] = 0;
for(int i = 1; i <= 100; ++i) {
memset(vis,0,sizeof(vis));
for(int j = 0; j < i; ++j) vis[sg[j]] = 1;
for(int j = 1; j <= i; ++j){
for(int jj = 1; jj <= i; ++jj) {
for(int k = 1; k <= i; ++k) {
if(j + jj + k == i) {
vis[sg[j] ^ sg[jj] ^ sg[k]] = 1;
}
}
}
}
for(int j = 0; j <= 1000; ++j) {
if(!vis[j]) {
sg[i] = j;
break;
}
}
cout<<i<<": " << sg[i]<<endl;
}
*/
int T,n,x;
scanf("%d",&T);
while(T--) {
scanf("%d",&n);
int ans = ;
for(int i = ; i <= n; ++i) {
scanf("%d",&x);
if((x+)% == ) {
ans ^= (x+);
} else if(x % == ) ans ^= (x-);
else ans ^= x;
}
if(!ans) puts("Second player wins.");else puts("First player wins."); }
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,086
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,561
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,410
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,183
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,820
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,903