D - Stone Division HackerRank - stone-division (博弈+搜索)
题目链接:https://cn.vjudge.net/problem/HackerRank-stone-division
题目大意:给你n,m,然后是m个数。每一次你可以选择一个a[i],如果能被n整除,然后n就被分成了a[i]堆,每一堆有n/a[i]个。问你谁先无法分。
具体思路:对于当前的a[i],如果是偶数的话,那么只要第二个人怎么做,第一个人模仿就行了,这个时候是必胜态。
如果是奇数的话,判断当前单独一堆里面有多少个,然后判断一下这个n是不是必胜的,如果不是,那么先手赢,否则后手赢。
谢谢lxw的讲解
AC代码:
#include<bits/stdc++.h>
using namespace std;
# define ll long long
const int maxn = 2e5+;
ll n,m;
map<ll,bool>sg;
ll a[maxn];
bool dfs(ll t)
{
if(sg.count(t))
return sg[t];
for(ll i=; i<=m; i++)
{
if(t%a[i])
continue;
if((a[i])%==)
{
sg[t]=;
return ;
}
else
{
if(!dfs(t/a[i]))
{
sg[t]=;
return ;
}
}
}
sg[t]=;
return ;
}
int main()
{
scanf("%lld %lld",&n,&m);
for(ll i=; i<=m; i++)
{
scanf("%lld",&a[i]);
}
if(dfs(n))
printf("First\n");
else
printf("Second\n");
return ;
}
D - Stone Division HackerRank - stone-division (博弈+搜索)的更多相关文章
- 【迭代博弈+搜索+剪枝】poj-1568--Find the Winning Move
poj 1568:Find the Winning Move [迭代博弈+搜索+剪枝] 题面省略... Input The input contains one or more test cas ...
- HDUOJ--------A simple stone game(尼姆博弈扩展)(2008北京现场赛A题)
A simple stone game ...
- hdu 4388 Stone Game II sg函数 博弈
Stone Game II comes. It needs two players to play this game. There are some piles of stones on the d ...
- POJ 1740 A New Stone Game(多堆博弈找规律)
传送门 //有n堆,AB轮流从n堆的一堆中移任意个,可以扔掉,也可以移给其他堆中的一堆 //最先移完的胜 //如果n堆中两两堆数目相等,那肯定是B胜 //但只要有非两两相同的,如xyz,A先, //A ...
- SGU 520 Fire in the Country(博弈+搜索)
Description This summer's heat wave and drought unleashed devastating wildfires all across the Earth ...
- B. Sleepy Game 博弈搜索
题意:给一个有向图和起点,然后只有一名选手,这名选手可以随意挪动棋子,最终不能动的时候走过的边为奇数边为Win并输出路径,否则如果有环输出Draw,否则输出Lose; 题目链接 知道状态数最多只有n* ...
- [08山东省选]2298 石子合并 即POJ 1738 An old Stone Game
2298 石子合并 2008年省队选拔赛山东 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 在 ...
- LN : leetcode 399 Evaluate Division
lc 399 Evaluate Division 399 Evaluate Division Equations are given in the format A / B = k, where A ...
- poj 1115 Lifting the Stone 计算多边形的中心
Lifting the Stone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
随机推荐
- JDBC的简单笔记
JDBC笔记: JDBC:java database connectivity SUN公司提供的一套操作数据库的标准规范. JDBC与数据库驱动的关系:接口与实现的关系. JDBC规范(掌握四个核心对 ...
- python基础-格式化时间
module datatime用strftime格式化时间import datetimedatetime.datetime.now() 返回microsecond,要修改datetime.dateti ...
- 关于python类变量和实例变量
今天在看python的类和实例的时候,突然发现了一个以前遗漏的点,也就是类变量和实例变量.首先需要理解一下类变量和实例变量的概念. 类全局变量:在类中定义,对类和由类生成的实例生效,如果通过方法对类变 ...
- DBMS客户端是否安装:Make sure DBMS client is installed and this required library is available for dynamic loading
Symptom The full error message is as follows:Error logging in. Unable to process the database trans ...
- CentOS 7 的安装
CentOS 7的安装 --------------------------- 安装前的准备: 1.去官网或是去网上下载好CentOS 7的镜像文件 下载主页: https://www.centos. ...
- mysql5.7 on windows
1.下载zip包:https://dev.mysql.com/downloads/file/?id=476696 2.解压到E盘3.执行命令 初始化 E:/mysql-5.7.22-winx64/bi ...
- 使用CMD 命令创建指定大小的文件
在做资源更新的时候要做 磁盘空间不足的测试,于是想创建一个文件塞满硬盘,搜索到可以用命令来创建. fsutil file createnew null.zip 524288000
- weblogic优化(内存、线程数和启动速度)
一.为服务分配内存 1.一般如果服务所需的内存不一样,需要单独指定的话,我们是通过拷贝startWebLogic.sh文件,拷贝为startNode.sh(名字随意) 2.然后在startNode.s ...
- MyBatis-CURD
一.接口方法 /** * 删除.修改.添加操作都可以返回三种类型 * Integer.Long.Boolean */ public interface MyUserMapper { public My ...
- JAVA核心技术I---JAVA基础知识(回顾)
一:对象实例化问题: public class Rectangle { ; ; public int area() { return width * height; } } 则如下代码输出结果为: R ...