D. Deleting Divisors

news/2024/10/24 20:12:27/

传送门:Problem - D - Codeforces

题意:

思路:博弈论

打表找规律( 递推 )

如果 ans[i] 为 true ,则 Alice 能赢   ans[i] 为 false,则 Bob 会赢

数字 n 的一个因子 为 x , 如果 ans[ n - x ] 为 false ( 必输态 ) ,则 ans[n] 是 true ( 必胜态 )

所以打表代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
bool ans[N];
bool test(int x)
{for (int i = 2; i <= x / i; i++){if (x % i == 0){if (!ans[x - i]) return true;if (!ans[x - x / i]) return true;}}return false;
}
signed main()
{for (int i = 1; i <= 110; i++){ans[i] = test(i);}for (int i = 1; i <= 110; i++)if (ans[i]) cout << i << " " << "Alice" << endl;else cout << i << " " << "Bob" << endl;
}

接下来观察结果,你会发现 当 n % 2 == 0 时,基本上就是 Alice,当有例外 2 8 32 等,你会发现这些数字都是 2 的奇数次幂

所以得到结论 当 if ( n % 2 == 1 || n 为 2 的奇数次幂 时 )  ,puts("Bob");

                           else  puts("Alice");

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define int long long
set<int> st;
void solve(){int n; cin >> n;if( n % 2 == 1 || st.count(n) )puts("Bob");else puts("Alice");
}
signed main()
{for( int i = 1 ; ( 1ll << i ) <= 1e9 ; i += 2 ){int temp = ( 1ll << i );st.insert( temp );}int tt; cin >> tt;while(tt--)solve();return 0;
}


http://www.ppmy.cn/news/1541653.html

相关文章

第10节 arkTS GridRow

在 ArkTS 中&#xff0c; GridRow 是 Grid 布局系统中的一个重要组成部分&#xff0c;用于定义网格布局中的行。以下是关于 GridRow 的详细介绍&#xff1a; 基本概念 Grid 布局将容器划分为行和列的网格结构&#xff0c; GridRow 则负责确定每行的属性和布局方式。…

2374. 边积分最高的节点

2374. 边积分最高的节点 题目链接&#xff1a;2374. 边积分最高的节点 代码如下&#xff1a; class Solution { public:int edgeScore(vector<int>& edges){int res 0;vector<long long> scores(edges.size());for (int i 0; i < edges.size(); i){int…

SSM义工活动系统-计算机毕业设计源码86760

目录 1 绪论 1.1 研究背景 1.2研究意义 1.3论文结构与章节安排 2 义工活动系统分析 2.1 可行性分析 2.2 系统功能分析 2.3 系统用例分析 2.4 系统流程分析 2.5本章小结 3 义工活动系统总体设计 3.1 系统功能模块设计 3.2 数据库设计 3.4本章小结 4 义工活动系统详…

数据结构和算法的常见面试题

关注B站可以观看更多实战教学视频&#xff1a;hallo128的个人空间 数据结构和算法的常见面试题 数据结构和算法是技术面试中的重点&#xff0c;尤其在软件工程师岗位。以下是一些常见的面试题&#xff0c;涵盖了不同的数据结构和算法&#xff1a; 一、数组与字符串 找出数组…

build bootable grub iso image hard disk

一、pre-work 1. 安装grub-install grub-mkrescue命令 apt install gub2-common grub-pc grub-efi-ia32 grub-efi-amd64:i386 grub-efi-amd64 二、iso image 1. bios iso #!/bin/shmkdir bios_iso mkdir -p bios_iso/boot/grubcp grub.cfg bios_iso/boot/grub/grub-mk…

Java全栈经典面试题剖析2】JavaSE面向对象1

目录 面试题2.1 JVM内存划分 a. 静态方法和栈帧 b. 程序计数器 c. 堆和栈中数据的默认值 d.局部变量表 e. 操作数栈 f. 静态解析/动态连接 g.方法出口 扩展(无需背诵) 面试题2.2 heap和stack有什么区别? 面试题2.3 面向对象的基本特征是什么&#xff1f; 面试题2.4 java…

docker-compose-lnmp-wordpress

使用 docker-compose 在 CentOS 7 上编写并部署 LNMP (Linux, Nginx, MySQL, PHP) 环境的 YAML 文章目录 部署步骤&#xff1a;1. 安装 Docker 和 Docker Compose1.1安装 Docker&#xff1a;1.2安装 Docker Compose&#xff1a; 2.创建目录结构3.编写docker-compose.yml4.ngin…

2023 icpc南京(待更新)

文章目录 [I. Counter](https://codeforces.com/gym/104821/problem/I)[C. Primitive Root](https://codeforces.com/gym/104821/problem/C)[F. Equivalent Rewriting](https://codeforces.com/gym/104821/problem/F)[G. Knapsack](https://codeforces.com/gym/104821/problem/…