http://uoj.ac/contest/6/problem/51

题意:给m($m \le 10^5$)个询问,每次给出$a, b(a^b \le n, n \le 10^9)$,对于每一组$a, b$,双人博弈,每次可以给$a$加1或给$b$加1,要求每次操作后$a^b \le n$。不能操作的算输。问先手是否必胜。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << (#x) << " = " << (x) << endl
#define error(x) (!(x)?puts("error"):0)
#define rdm(x, i) for(int i=ihead[x]; i; i=e[i].next)
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } const int N=1e5+10;
int f[N][33], mx[N];
ll n; int ask(int a, int b) {
if((ll)a*a>n) { if(b>1) return 0; return !((n-a)&1); }
if(b>mx[a]) return 0;
if(f[a][b]!=-1) return f[a][b];
if(!ask(a+1, b) && !ask(a, b+1)) return f[a][b]=1;
return f[a][b]=0;
}
void init() {
int sq=sqrt(n+0.5);
for1(i, 2, sq) {
int cnt=1; ll now=i;
while(now*i<=n) {
++cnt;
now*=i;
} //dbg(cnt);
mx[i]=cnt;
}
}
int main() {
read(n);
CC(f, -1);
int m=getint();
init();
while(m--) {
int a=getint(), b=getint();
!ask(a, b)?puts("Yes"):puts("No");
}
return 0;
}

显然指数大于等于2的底数小于等于$sqrt(n)$,当底数大于了$sqrt(n)$我们能够根据奇偶判断胜负

然后有$sqrt(n)$个底数,每个底数最多不超过$log n=31$,所以直接记忆化暴力...复杂度$O(sqrt(n)logn)$

【UR #4】元旦三侠的游戏(博弈论+记忆化)的更多相关文章

  1. 【uoj#51】[UR #4]元旦三侠的游戏 博弈论+dp

    题目描述 给出 $n$ 和 $m$ ,$m$ 次询问.每次询问给出 $a$ 和 $b$ ,两人轮流选择:将 $a$ 加一或者将 $b$ 加一,但必须保证 $a^b\le n$ ,无法操作者输,问先手是 ...

  2. 【UOJ#51】【UR #4】元旦三侠的游戏(博弈论)

    [UOJ#51][UR #4]元旦三侠的游戏(博弈论) 题面 UOJ 题解 考虑暴力,\(sg[a][b]\)记录\(sg\)函数值,显然可以从\(sg[a+1][b]\)和\(sg[a][b+1]\ ...

  3. [UOJ Round#4 A] [#51] 元旦三侠的游戏 【容斥 + 递推】

    题目链接:UOJ - 51 据说这题与 CF 39E 类似. 题目分析 一看题目描述,啊,博弈论,不会!等待爆零吧... 这时,XCJ神犇拯救了我,他说,这题可以直接搜啊. 注意!是用记忆化搜索,状态 ...

  4. [UOJ #51]【UR #4】元旦三侠的游戏

    题目大意:给$n$,一个游戏,给$a,b$,两个人,每人每次可以把$a$或$b$加一,要求$a^b\leqslant n$,无法操作人输.有$m$次询问,每次给你$a,b$,问先手可否必胜 题解:令$ ...

  5. A. 【UR #4】元旦三侠的游戏

    题解: 挺水的吧 会发现当b不等于1的时候,状态只有sigma i x^(1/i) 显然这东西很小.. 然后我们会发现每个点向两个点动 定义必胜点和必败点 当一个点有一条边连向必败点 那么它就是必胜点 ...

  6. uoj51 元旦三侠的游戏

    题意:询问a,b,n.每次可以a+1或b+1,保证a^b<=n,不能操作者输.问先手是否赢? n<=1e9. 标程: #include<cstdio> #include< ...

  7. hdu 4753 Fishhead’s Little Game 博弈论+记忆化搜索

    思路:状态最多有2^12,采用记忆化搜索!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm& ...

  8. poj 1085 Triangle War 博弈论+记忆化搜索

    思路:总共有18条边,9个三角形. 极大极小化搜索+剪枝比较慢,所以用记忆化搜索!! 用state存放当前的加边后的状态,并判断是否构成三角形,找出最优解. 代码如下: #include<ios ...

  9. cf787c 博弈论+记忆化搜索

    好题,单纯的就是pn状态的推导 /* 把第一个点标为0,剩下的点按1-n-1编号 胜态是1,败态为0,dp[i][j]表示第i个人,怪兽起始位置在j时的胜负态 把0点设置为必败态,然后对于一个人来说, ...

随机推荐

  1. HDOJ 1102 生成树

    Constructing Roads Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. set_include_path详细解释

    zendframework的示例index.php里有这样一句 set_include_path('.' . PATH_SEPARATOR . '../library/'. PATH_SEPARATO ...

  3. Shell之date用法

    创建以当前时间为文件名的 mkdir `date+%Y%m%d` 备份以时间做为文件名的 tar cvf./htdocs`date +%Y%m%d`.tar ./* date命令如何获得上星期的日期? ...

  4. 【leetcode】3Sum Closest

    3Sum Closest Given an array S of n integers, find three integers in S such that the sum is closest t ...

  5. C++基础知识面试精选100题系列(1-10题)[C++ basics]

    [原文链接] http://www.cnblogs.com/hellogiser/p/100-interview-questions-of-cplusplus-basics-1-10.html [题目 ...

  6. BSD学习(BSD系统的历史和目标)

    UNIX系统的历史 unix系统的发展历程大概经历以下几个阶段: 贝尔实验室(Bell Laboratories)阶段,该实验室发明了UNIX 加州大学伯克利分校(University of Cali ...

  7. 编译qt

    进入开始菜单Microsoft Visual Studio 2010,Visual Studio Tools,Visual Studio Command Prompt (2010),需要注意的是,这里 ...

  8. 谈谈异步加载JavaScript

    前言 关于JavaScript脚本加载的问题,相信大家碰到很多.主要在几个点—— 1> 同步脚本和异步脚本带来的文件加载.文件依赖及执行顺序问题 2> 同步脚本和异步脚本带来的性能优化问题 ...

  9. cocos2dx实现经典飞机大战

    游戏开始层 #ifndef __LayerGameStart_H__ #define __LayerGameStart_H__ #include "cocos2d.h" USING ...

  10. 以多个实例方式打开Notepad++

    Right-click any Notepad++ shortcut. Select Properties. Move to the Shortcut tab. In the end of the T ...