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 ...
随机推荐
- 第三十五节,目标检测之YOLO算法详解
Redmon, J., Divvala, S., Girshick, R., Farhadi, A.: You only look once: Unified, real-time object de ...
- 对C# .Net4.5异步机制测试(二)——加深印象
public static void Main() { Console.WriteLine(Thread.CurrentThread.ManagedThreadId); In(); Console.W ...
- RabbitMQ入门-发布订阅模式
兔子的Publish/Subscribe是这样的: 有个生产者P,X代表交换机,交换机绑定队列,消费者从队列中取得消息.每次有消息,先发到交换机中,然后由交换机负责发送到它已知的队列中. 生产者代码: ...
- ES6---扩展运算符和rest‘...’(三点运算符),在数组、函数、set/map等中的应用
ES6新增的三点运算符,是由三个点表示,在数组中扮演着重要的角色,可以对数组进行合并与分解.可以对set等数据结构进行转换.可以对函数参数进行简化表示,接下来,我们一起揭开其神秘面纱… ●三点—res ...
- Doing Homework HDU - 1074 (状压dp)
Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...
- PHP生成四角图片
<?php /** 圆角 $radius = 100; $img = imagecreatetruecolor($radius, $radius); // 创建一个正方形的图像 $bgcolor ...
- 网速测试脚本speedtest_cli的安装与使用
speedtest_cli的安装与使用 1.下载 wget https://raw.github.com/sivel/speedtest-cli/master/speedtest.py 图 1 2.授 ...
- Struts2_参数获得方式
1.属性驱动 /** * @ClassName: Demo8Action * @Description: struts2如何获得参数 * 每次请求action时都会创建新的action实例对象 * @ ...
- nginx之代理websocket
nginx代理websocket:NGINX通过允许一个在客户端和后端服务器之间建立的隧道来支持WebSocket.为了NGINX发送来至于客户端Upgrade请求到后端服务器,Upgrade和Con ...
- mysql清理binlog日志
mysql的binlog日志过多过大,清理过程. 1.查看binlog日志 mysql> show binary logs; +------------------+-----------+ | ...