FZYZ-2071 A Simple Math Problem IX
P2071 -- A Simple Math Problem IX
时间限制:1000MS 内存限制:262144KB
状态:Accepted 标签: 数学问题-博弈论 无 无
Description
给定a,b,n,保证a≥2,b≥1,a^b≤n。两个人在玩游戏,每个人每次可以把a加1,或者把b加1,但是不能违反a^b<=n,无法再进行操作的人就输掉了这一场游戏。
假设两个人都足够聪明,按照最优策略进行游戏,问先手是否有必胜策略。
Input Format
第一行两个正整数 n 和 m。
接下来 m 行,每行两个正整数 a 和 b。保证 a≥2,b≥1,a^b≤n。
Output Format
m 行,如果对于这一对数字 a 和 b,如果先手有必胜策略,输出 “Yes”。否则输出 “No” (不含引号)
Sample Input
5 3 2 1 2 2 3 1
Sample Output
Yes No No
Hint
对于10%的数据,n=2
对于70%的数据,n<=1000
对于100%的数据,n<=10^9,m<=10^5
题解
不难想到,状态(a,b)可以转移到状态(a + 1, b)或者(a, b + 1)。设F[a][b]为该局面下先手胜败,1表示必胜,0表示必败,那么F[a][b] = (F[a + 1][b] & F[a][b +1]) ^ 1。但是数据范围太大,该怎么办呢?
首先,a和b必须满足a^b <= n,即log (a, n) >= b,又因为a >= 2,所以log (2, n) >= log(a, n),所以b <= log (2, n) <= 30。
其次,a^b <= n还可以推出当b >= 2时,a <= sqrt(n),这也是一个不大的数字。当b=1时,即便n很大,但随着a的递增,可供选择的b会逐渐减少,最后转移会变成一条链,所以根据奇偶性判断就好。
代码
1 #include <cstdio> 2 #include <iostream> 3 #include <cmath> 4 #include <cstring> 5 #define MAXN 50010 6 #define MAXM 50 7 using namespace std; 8 9 int N, M; 10 int j; 11 long long X; 12 int A, B; 13 int Lim; 14 bool F[MAXN][MAXM]; 15 16 char ch; int aa, bb; 17 int Scan() { 18 while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-'); 19 ch=='-' ? (bb=1,aa=0) : (aa=ch-48,bb=0); 20 while(ch=getchar(),ch>='0'&&ch<='9')aa=aa*10+ch-48; 21 if(bb)aa=-aa; 22 return aa; 23 } 24 25 int main() { 26 memset(F, 1, sizeof(F)); //F必须开bool 27 N = Scan(); 28 Lim = int (sqrt(N)); 29 if ((Lim + N) & 1) F[Lim + 1][1] = 0; 30 for (int i = Lim; i >= 2; --i) { 31 for (j = 0, X = 1; X <= N; X *= i, ++j); //X可能会爆int 32 for (--j; j; --j) F[i][j] = (F[i + 1][j] & F[i][j + 1]) ^ 1; 33 } 34 for (M = Scan(); M; --M) { 35 A = Scan(); B = Scan(); 36 if (B == 1 && A > Lim) { 37 if ((N + A) & 1) printf("Yes\n"); 38 else printf("No\n"); 39 } 40 else { 41 if (F[A][B]) printf("Yes\n"); 42 else printf("No\n"); 43 } 44 } 45 }
转载于:https://www.cnblogs.com/DonMaestro/p/4324207.html
FZYZ-2071 A Simple Math Problem IX相关推荐
- A Simple Math Problem(2020 ICPC 江西省省赛)
A Simple Math Problem ∑i=1n∑j=1if(j)[gcd(i,j)=1]∑i=1n∑j=inf(i)[gcd(i,j)=1]∑i=1n∑j=1nf(i)[gcd(i,j)=1] ...
- A Simple Math Problem 矩阵打水题
A Simple Math Problem Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x ...
- A Simple Math Problem题目翻译
A Simple Math Problem | JXNUOJhttps://acs.jxnu.edu.cn/problem/ICPCJX2020A 描述: Huanhuan challenges yo ...
- 1.24A Simple Math Problem
原网址:https://acs.jxnu.edu.cn/problem/NOIOPJCH02077215 描述: Huanhuan challenges you to a simple math pr ...
- HDU - 5974 A Simple Math Problem 题解
D - Simple Math Problem 戳上方进入原题哟~ 题目大意 给一个数 a,b. 让你求满足一下条件的 X,Y: X+Y = a LCM(X,Y) = b 解析 题目给出时间限制1s, ...
- Simple Math Problem
Simple Math Problem | JXNUOJ 翻译: 描述: 通通又在玩数学游戏.她已经多次遇到这个方针了,所以不用说,她知道你说的是什么.现在她将这个问题推给你.你需要观察下面的方阵,然 ...
- HDU 1757 A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
- hdu A Simple Math Problem
Problem Description Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x & ...
- A Simple Math Problem(矩阵快速幂)
Lele now is thinking about a simple function f(x). If x < 10 f(x) = x. If x >= 10 f(x) = a0 * ...
最新文章
- Nginx PHP 报504 Gateway time-out错误的解决方法
- Sorting It All Out--POJ 1094
- 架构师成长之路:如何提升技术掌控力?
- nodejs随记04
- excel中如何添加下拉选择框
- 高中电子技术——三极管的放大特性和开关特性
- 时间格式转变 android,Android开发日期时间格式的转化
- Activiti7实战-入门
- Java电子签章验章知识储备
- 全栈python之路——三篇文章带你踏入python大门-基础01
- (1)桌面客制化之单屏幕修改以及wight修改
- 三星引入ChatGPT半个月泄密3次;MidJourney V5相机镜头完整参数列表;万字长文,拆解投身大模型3个本质问题 | ShowMeAI日报
- 一口气推荐16个让人震惊的黑科技工具
- widget安卓桌面插件初步使用
- 同步与异步区别之我见(一)
- 通过电气化来减少排放量 - 白皮书
- 网络流量 pv、uv、ip 各代表的含义
- 围观饱醉豚与众程序员互怼有感
- 变形金刚3 部分台词
- 8.3.7-8.3.8