UVA 1482 - Playing With Stones 题目链接 题意:给定n堆石头,每次选一堆取至少一个.不超过一半的石子,最后不能取的输,问是否先手必胜 思路:数值非常大.无法直接递推sg函数.打出前30项的sg函数找规律 代码: #include <stdio.h> #include <string.h> int t, n; long long num; long long SG(long long x) { return x % 2 == 0 ? x : SG(x /…
C - Playing With Stones Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Practice UVALive 5059 Description You and your friend are playing a game in which you and your friend take turns removing stones from piles.…
打出SG表来可以很容易的发现i为偶数时 SG[i]=i/2 i为奇数时 SG[i]=SG[i/2] #include<bits/stdc++.h> typedef long long ll; using namespace std; ll SG(ll x) { ?SG(x/):x/; } int main() { int t; scanf("%d", &t); while (t--) { int n; ll a, v = ; scanf("%d"…
Code: #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll SG(ll i){ return i % 2 ==0 ? i / 2 : SG(i/2); } ll arr[100000]; int main(){ //freopen("input.in","r",stdin); int T; scanf("%d&quo…
Description Games Are Important One of the primary hobbies (and research topics!) among Computing Science students at the University of Alberta is, of course, the playing of games. People here like playing games very much, but the problem is that t…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 613 Accepted Submission(s): 282 Problem Description Nim is a two-player mathematic game of strategy in which players take turns…
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)…
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #include <bits/stdc++.h> using namespace std; typedef long long LL; ; ], maxs; int vis[maxn]; //yu控制递归层数,cur控制所分配最大值,next控制所分配最小值 void dfs(int cur, int yu…
10067 - Playing with Wheels 题目页:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1008 从一开始思路就不对,之后才焕然大悟……每次都是这样. 还有,感觉搜索和图遍历有点分不清呢. 在第63行加入 if (u == target) return; 可以提速很多,可以从300ms左右降低到100ms以内. ?…
UVA 11927 - Games Are Important option=com_onlinejudge&Itemid=8&page=show_problem&category=478&problem=3078&mosmsg=Submission+received+with+ID+13891171" target="_blank" style="">题目链接 题意:给定一个有向图,结点上有一些石头,两人轮流…
Boxes and Stones Paul and Carole like to play a game with S stones and B boxes numbered from 1 to B. Beforebeginning the game they arbitrarily distribute the S stones among the boxes from 1 to B - 1, leavingbox B empty. The game then proceeds by roun…
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1714 nim游戏的一个变形,需要打出sg函数的表 #include <bits/stdc++.h> using namespace std; typedef long long LL; ; ], maxs; int vis[maxn]; //yu控制递归层数,cur控制所分配最大值,next控制所分配最小值 void dfs(int cur, int yu…
Joseph The Joseph's problem is notoriously known. For those who are not familiar with the original problem: from among n people, numbered 1, 2, ..., n, standing in circle every mth is going to be executed and only the life of the last remaining per…
题意:有n堆石子,每次可以将其中一堆分为数量不为0的3堆,或者从其中一堆中拿走若干个,最终拿完的那个人赢. 思路:直接暴力SG状态,然后找出其中的规律,异或一下每一堆的状态就可以了. #include<bits/stdc++.h> using namespace std; typedef long long ll; ;bool flag[maxn]; int sg[maxn]; int getSg(int x){ ) return sg[x]; memset(flag, , sizeof(fl…
Given the value of N, you will have to find the value of G. The definition of G is given below:Here GCD(i, j) means the greatest common divisor of integer i and integer j.For those who have trouble understanding summation notation, the meaning of G i…
题意:nim游戏.加上限制每次不得取走超过当前堆一半的石子 1 ≤ N ≤ 100,1 ≤ ai ≤ 2 ∗ 1018 分析:由于ai过大.所以我们采用SG函数递推找规律. (详见代码) #include<cstdio> using namespace std; typedef long long ll; int T,n;ll x,S; ll GetSG(ll x){ ?GetSG(x>>):x>>; } int main(){ for(scanf("%d&q…