Uva--10404(动规,博弈)

本文介绍了一种基于Bachet's Game的博弈问题,通过动态规划方法确定两名玩家Stan与Ollie的胜负策略。游戏初始有n个石头,玩家轮流移除一定数量的石头,最终移除最后一个石头的玩家获胜。

2014-08-02 16:13:18

Problem B: Bachet's Game

Bachet's game is probably known to all but probably not by this name. Initially there are n stones on the table. There are two players Stan and Ollie, who move alternately. Stan always starts. The legal moves consist in removing at least one but not more than k stones from the table. The winner is the one to take the last stone.

Here we consider a variation of this game. The number of stones that can be removed in a single move must be a member of a certain set ofm numbers. Among the m numbers there is always 1 and thus the game never stalls.

Input

The input consists of a number of lines. Each line describes one game by a sequence of positive numbers. The first number is n <= 1000000 the number of stones on the table; the second number is m <= 10 giving the number of numbers that follow; the last m numbers on the line specify how many stones can be removed from the table in a single move.

Input

For each line of input, output one line saying either Stan wins or Ollie wins assuming that both of them play perfectly.

Sample input

20 3 1 3 8
21 3 1 3 8
22 3 1 3 8
23 3 1 3 8
1000000 10 1 23 38 11 7 5 4 8 3 13
999996 10 1 23 38 11 7 5 4 8 3 13

Output for sample input

Stan wins
Stan wins
Ollie wins
Stan wins
Stan wins
Ollie wins

思路:很有意思的一道题目,结合了博弈的知识。首先dp[k]表示还剩k个石头的状态,dp[k] == 1表示必胜态,dp[k] == 0表示必败态。
  由两条博弈准则:
  1:当前状态为必胜态,当且仅当他的后继状态中至少有一个必败态。
  2:当前状态为必败态,当且仅当他的后继状态全部都为必胜态。
而这题只用到了 1 准则,dp[0]必为必败态(因为没有剩余的石头可取了),所以可以从dp[0]开始往起点dp[n]推即可。
 1 /*************************************************************************
 2     > File Name: f.cpp
 3     > Author: Nature
 4     > Mail: 564374850@qq.com 
 5     > Created Time: Wed 30 Jul 2014 04:10:19 PM CST
 6 ************************************************************************/
 7 
 8 #include <cstdio>
 9 #include <cstring>
10 #include <cstdlib>
11 #include <cmath>
12 #include <iostream>
13 #include <algorithm>
14 using namespace std;
15 
16 int n,m,v[15];
17 int dp[1000005];
18 
19 int main(){
20     while(scanf("%d%d",&n,&m) == 2){
21         memset(dp,-1,sizeof(dp));
22         for(int i = 0; i < m; ++i)
23             scanf("%d",&v[i]);
24         for(int i = 0; i <= n; ++i){
25             dp[i] = 0;
26             for(int j = 0; j < m; ++j){
27                 if(i - v[j] >= 0 && !dp[i - v[j]]){
28                     dp[i] = 1;
29                     break;
30                 }
31             }
32 
33         }
34         if(dp[n])
35             printf("Stan wins\n");
36         else
37             printf("Ollie wins\n");
38     }
39     return 0;
40 }

 


转载于:https://www.cnblogs.com/naturepengchen/articles/3887116.html

先看效果: https://renmaiwang.cn/s/jkhfz Hue系列产品将具备高度的个性化定制能力,并且借助内置红、蓝、绿三原色LED的灯泡,能够混合生成1600万种不同色彩的灯光。 整个操作流程完全由安装于iPhone上的应用程序进行管理。 这一创新举措为智能照明控制领域带来了新的启示,国内相关领域的从业者也积极投身于相关研究。 鉴于Hue产品采用WiFi无线连接方式,而国内WiFi网络尚未全面覆盖,本研究选择应用更为普及的蓝牙技术,通过手机蓝牙与单片机进行数据交互,进而产生可调节占空比的PWM信号,以此来控制LED驱电路,实现LED的调光功能以及DIY调色方案。 本文重点阐述了一种基于手机蓝牙通信的LED灯设计方案,该方案受到飞利浦Hue智能灯泡的启发,但考虑到国内WiFi网络的覆盖限制,故而选用更为通用的蓝牙技术。 以下为相关技术细节的详尽介绍:1. **智能照明控制系统**:智能照明控制系统允许用户借助手机应用程序实现远程控制照明设备,提供个性化的调光及色彩调整功能。 飞利浦Hue作为行业领先者,通过红、蓝、绿三原色LED的混合,能够呈现1600万种颜色,实现了全面的定制化体验。 2. **蓝牙通信技术**:蓝牙技术是一种低成本、短距离的无线传输方案,工作于2.4GHz ISM频段,具备即插即用和强抗干扰能力。 蓝牙协议栈由硬件层和软件层构成,提供通用访问Profile、服务发现应用Profile以及串口Profiles等丰富功能,确保不同设备间的良好互操作性。 3. **脉冲宽度调制调光**:脉冲宽度调制(PWM)是一种高效能的调光方式,通过调节脉冲宽度来控制LED的亮度。 当PWM频率超过200Hz时,人眼无法察觉明显的闪烁现象。 占空比指的...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值