HDU 1517 A Multiplication Game (SG函数找规律)
题意:两个玩家玩一个游戏,从 p = 1,开始,然后依次轮流选择一个2 - 9的数乘以 p,问你谁先凑够 p >= n。
析:找规律,我先打了一下SG函数的表,然后就找到规律了
我找到的是:
1 - 9 Stan wins. 1 ~ 9
10 - 18 Ollie wins. 9+1 ~ 9*2
19 - 162 Stan wins. 9*2+1 ~ 9*2*9
163 - 324 Ollie wins. 9*2*9+1 ~ 9*2*9*2
325 - 2916 Stan wins. 9*2*9*2+1 ~ 9*2*9*2*9
2917 - 5832 Ollie wins. 9*2*9*2*9+1 ~ 9*2*9*2*9*2
规律就很明显了。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
#include <map>
#include <cctype>
#include <cmath>
#include <stack>
#include <sstream>
#include <list>
#include <assert.h>
#include <bitset>
#include <numeric>
#define debug() puts("++++")
#define gcd(a, b) __gcd(a, b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define fi first
#define se second
#define pb push_back
#define sqr(x) ((x)*(x))
#define ms(a,b) memset(a, b, sizeof a)
#define sz size()
#define pu push_up
#define pd push_down
#define cl clear()
#define lowbit(x) -x&x
//#define all 1,n,1
#define FOR(i,x,n) for(int i = (x); i < (n); ++i)
#define freopenr freopen("in.txt", "r", stdin)
#define freopenw freopen("out.txt", "w", stdout)
using namespace std; typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
const int INF = 0x3f3f3f3f;
const LL LNF = 1e17;
const double inf = 1e20;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int maxn = 1000 + 10;
const int maxm = 100 + 2;
const LL mod = 100000000;
const int dr[] = {-1, 1, 0, 0, 1, 1, -1, -1};
const int dc[] = {0, 0, 1, -1, 1, -1, 1, -1};
const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
int n, m;
const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline bool is_in(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < m;
} int main(){
unsigned int n;
while(scanf("%d", &n) == 1){
LL p = 1;
while(1){
p *= 9;
if(p >= n){ puts("Stan wins."); break; }
p *= 2;
if(p >= n){ puts("Ollie wins."); break; }
}
}
return 0;
}
HDU 1517 A Multiplication Game (SG函数找规律)的更多相关文章
- BZOJ 1228 E&G(sg函数+找规律)
把一对石子堆看出一个子游戏.打出子游戏的sg表找规律.. 这个规律我是一定找不出来的... 对于i,j,如果 (i-1)%pow(2,k+1) < pow(2,k) (j-1)%pow(2,k+ ...
- HDU-4664 Triangulation 博弈,SG函数找规律
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4664 题意:一个平面上有n个点(一个凸多边形的顶点),每次可以连接一个平面上的两个点(不能和已经连接的 ...
- hdu 1847 博弈基础题 SG函数 或者规律2种方法
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- 51nod_1661: 黑板上的游戏(sg函数 找规律)
题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...
- 51nod 1661: 黑板上的游戏(sg函数 找规律)
题目链接 先打一个sg函数的表,找找规律,发现sg函数可以递归求解 打表代码如下 #include<bits/stdc++.h> using namespace std; typedef ...
- HDU 1847 Good Luck in CET-4 Everybody!(找规律版巴什博奕)
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 【poj 3090】Visible Lattice Points(数论--欧拉函数 找规律求前缀和)
题意:问从(0,0)到(x,y)(0≤x, y≤N)的线段没有与其他整数点相交的点数. 解法:只有 gcd(x,y)=1 时才满足条件,问 N 以前所有的合法点的和,就发现和上一题-- [poj 24 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- HDU 1536 S-Nim (组合游戏+SG函数)
题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...
随机推荐
- 小程序循环多个picker选择器,实现动态增、减
现象 循环picker选择器,改变一个下拉框选项,导致全部下拉框选项改变: 问题 怎样操作才能实现只改变当前操作的下拉框的值? 思路 在js中设置一个数组变量,存储每个picker选择器默认的值:然后 ...
- .netcore webapi 在startup中读取配置字符串
参考微软官方说明:https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration 具体为: 读取方法见下图中标红的格式, ...
- 不使用SwitchHosts修改C:\Windows\System32\drivers\etc\hosts文件
1.nginx中的nginx.conf完成修改,配置好了端口和域名www.xuecheng.com 2.找到Hosts文件,将Hosts文件复制到桌面.(Windows 10系统Hosts文件路径为: ...
- IIS站点报拒绝访问Temporary ASP.NET Files的解决办法
IIS站点本来运行的好好的,突然就出现了:Temporary ASP.NET Files拒绝访问的问题.遇到此类问题,请逐步排查,定可解决. 原因:Windows操作系统升级导致. 办法: 1.检查C ...
- 制作根文件系统之内核如何启动init进程
start_kernel其实也是内核的一个进程,它占用了进程号0,start_kernel的内容简写如下: asmlinkage void __init start_kernel(void) //内核 ...
- Materix3*3
][],][],][]) { ;i<;i++) { ;j<;j++) { res[i][j]= aa[i][] * bb[][j] + aa[i][] *bb[][j] + aa[i][] ...
- c#多线程下的进程同步SignalAndWait 使用简单说明
解释:向一个 WaitHandle 发出信号并等待另一个进入信号. 总体概述: .NET Framework中提供一些类用于手动进行线程间的访问同步.这些类主要分为3大类别(但正如下文中会看到的这些类 ...
- android studio 安装过程
下载 安装版本:3.0.1 下载地址:https://pan.baidu.com/s/1Uq6QSZXpmWUiBW6K-tRqKw 密码:zbtb 安装 双击安装包进行安装,选择安装位置,安装完成打 ...
- C# 通过api函数GetPrivateProfileString读取ini文件,取不到值
通过api函数GetPrivateProfileString读取ini文件,取不到值,测试了好长时间,都不行 确认程序,ini文件都没有错误的情况,最后发现是ini文件编码的原因. 将ini文件的编码 ...
- hdu 1254(两个BFS) 推箱子
http://acm.hdu.edu.cn/showproblem.php?pid=1254 首先,要判断人是不是可以从4到达箱子的位置2,而且不止判断一次,因为推动箱子一步后,人的位置也会改变,所以 ...