博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1729(石子)
阅读量:2125 次
发布时间:2019-04-30

本文共 993 字,大约阅读时间需要 3 分钟。

题意

一共有n个箱子,每个箱子容量为S,当前的石子为C。每次想一个箱子放石子,放的数量不能超过当前石子数的平方,谁先放完谁赢。

AC

SG函数

  • 当C == S 时,sg(S, C) = 0
  • 当C > T 时,假设T为当前最大的必败点,则T满足 T + T * T < S, (T + 1) + (T + 1) * (T + 1) >= S
    sg(S, C) = mex(sg(S, C + 1), sg(S, C + 2) …… sg(S, S - 1), sg(S, S)) = S - C
    证明:sg(S, S) = 0, sg(S, S - 1) = mex(sg(S, S)) = 1 ………
  • 当C <= T,此时sg(S, C) = sg(T, C),递归求sg
#include 
#include
#include
#include
#include
#include
#include
#include
#define N 100005#define P pair
#define mk(a, b) make_pair(a, b)#define mem(a, b) memset(a, b, sizeof(a))int inf = 0x3f3f3f3f;#define ll long longusing namespace std;int get_sg(int s, int c) { // 求最大必败点 int q = sqrt(s); while (q + q * q >= s) q--; if (c > q) return s - c; else return get_sg(q, c);}int main(){ int Case = 1; int n; while (cin >> n, n) { int ans = 0; while (n--) { int s, c; cin >> s >> c; ans ^= get_sg(s, c); } cout << "Case " << Case++ << ":" << endl; if (ans) cout << "Yes\n"; else cout << "No\n"; } return 0;}

转载地址:http://qzprf.baihongyu.com/

你可能感兴趣的文章
谈谈编程思想
查看>>
iOS MapKit导航及地理转码辅助类
查看>>
检测iOS的网络可用性并打开网络设置
查看>>
简单封装FMDB操作sqlite的模板
查看>>
iOS开发中Instruments的用法
查看>>
iOS常用宏定义
查看>>
什么是ActiveRecord
查看>>
有道词典for mac在Mac OS X 10.9不能取词
查看>>
关于“团队建设”的反思
查看>>
利用jekyll在github中搭建博客
查看>>
Windows7中IIS简单安装与配置(详细图解)
查看>>
linux基本命令
查看>>
BlockQueue 生产消费 不需要判断阻塞唤醒条件
查看>>
强引用 软引用 弱引用 虚引用
查看>>
数据类型 java转换
查看>>
"NetworkError: 400 Bad Request - http://172.16.47.117:8088/rhip/**/####t/approval?date=976
查看>>
mybatis 根据 数据库表 自动生成 实体
查看>>
win10将IE11兼容ie10
查看>>
checkbox设置字体颜色
查看>>
第一篇 HelloWorld.java重新学起
查看>>