BZOJ 1228 E&G(sg函数+找规律)

把一对石子堆看出一个子游戏。打出子游戏的sg表找规律。。

这个规律我是一定找不出来的。。。

对于i,j,如果

(i-1)%pow(2,k+1) < pow(2,k)

(j-1)%pow(2,k+1) < pow(2,k)

那么最小的k值就是sg值。

# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <set>
# include <cmath>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-9
# define MOD 1000000000
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
int Scan() {
    int x=0,f=1;char ch=getchar();
    while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
    while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
    return x*f;
}
void Out(int a) {
    if(a<0) {putchar(‘-‘); a=-a;}
    if(a>=10) Out(a/10);
    putchar(a%10+‘0‘);
}
const int N=20005;
//Code begin...

int a[N];

int sg(int x, int y){
    LL tmp=2;
    for (int i=0; ; ++i, tmp<<=1) if ((x-1)%tmp<tmp/2 && (y-1)%tmp<tmp/2) return i;
}
int main ()
{
    int T, n;
    scanf("%d",&T);
    while (T--) {
        int ans=0;
        scanf("%d",&n);
        FOR(i,1,n) scanf("%d",a+i);
        FOR(i,1,n/2) ans^=sg(a[2*i-1],a[2*i]);
        puts(ans?"YES":"NO");
    }
    return 0;
}

时间: 2024-10-08 20:13:31

BZOJ 1228 E&G(sg函数+找规律)的相关文章

poj 3090 (欧拉函数,找规律)

poj 3090 (欧拉函数,找规律) 题目: 给出一个n*n的点阵,求从(0,0)出发斜率不相等的直线有多少条. 限制: 1 <= n <= 1000 思路: 先定义sum[i] sum[i] = 0, if(i == 1) sum[i] = sum[i-1] + phi[i], if(i >= 2) ans = sum[n] * 2 + 3 /*poj 3090 题目: 给出一个n*n的点阵,求从(0,0)出发斜率不相等的直线有多少条. 限制: 1 <= n <= 100

HDU 5795 A Simple Nim 打表求SG函数的规律

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).T

BZOJ 3895: 取石子[SG函数 搜索]

有N堆石子 ·从某堆石子中取走一个 ·合并任意两堆石子 不能操作的人输. 100%的数据满足T<=100,  N<=50. ai<=1000 容易发现基础操作数$d=\sum a_i +n-1$ 没有个数为1的堆还好说,有的话@#$%^&好麻烦啊啊啊啊啊怎么可能找规律 然后看题解,woc记忆化搜索 $f(i,j)$表示i个个数为1的堆,其他操作数为j的胜负态 枚举操作转移就行了,一定要枚举对!注意$j=1$时 #include <iostream> #include

hdu-5597 GTW likes function(欧拉函数+找规律)

题目链接: GTW likes function Time Limit: 4000/2000 MS (Java/Others)     Memory Limit: 131072/131072 K (Java/Others) Problem Description Now you are given two definitions as follows. f(x)=∑xk=0(−1)k22x−2kCk2x−k+1,f0(x)=f(x),fn(x)=f(fn−1(x))(n≥1) Note that

BZOJ 1002 FJOI 2007 轮状病毒 暴力+找规律+高精度

题目大意: 思路:基尔霍夫矩阵求生成树个数,不会. 但是可以暴力打表.(我才不会说我调试force调试了20分钟... CODE(force.cc): #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define MAX 1000 using namespace std; struct Edge{ int x,y; Edge(int _,int __

bzoj 1002 [FJOI2007]轮状病毒——打表找规律

题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1002 看 Zinn 的博客:https://www.cnblogs.com/Zinn/p/9252831.html 时隔六个月,自己终于也 A 了这道题. #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define db double using name

2018南京区域赛G题 Pyramid——找规律&amp;&amp;递推

先手动推出前10项,再上BM板子求出递推式 $A_n = 5A_{n-1} - 10A_{n-2} + 10A_{n-3} - 5A_{n-4} + A_{n-5}$,根据特征根理论可求出特征方程 $(x-1)^5$,设 $A_n = k_1n^4 + k_2n^3 + k_3n^2+k_4n+k_5$,代入前5项求出系数(用了高斯消元法解方程组). 这样虽然做出来了,但是感觉比较浪费时间,因为BM板子和高斯消元法的板子都不短,对手残狗不友好. 差分 首先前7项分别为1  5 15 35 70

Light OJ 1296 - Again Stone Game (博弈sg函数递推)

F - Again Stone Game Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Description Alice and Bob are playing a stone game. Initially there are n piles of stones and each pile contains some stone. Alice stars the

UVA 1482 - Playing With Stones(SG打表规律)

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 /