Cutting Game---博弈
2016-04-04 22:54
309 查看
#include "iostream" #include "vector" #include "string.h" #include "set" using namespace std; int mem[200][200]; int grundy(int w, int h) { if(mem[w][h] != -1) return mem[w][h]; int i; set<int> s; for(i=2; w-i>=2; i++) //如果切完后宽度为1,输 { //切出的两张纸的grundy值分别为g1, g2, 这两张纸对应状态的grundy值为g1 ^ g2 s.insert(grundy(i, h) ^ grundy(w-i, h)); } for(i=2; h-i>=2; i++) //如果切完后高度为1,输 { s.insert(grundy(w, i) ^ grundy(w, h-i)); } int g = 0; while(s.count(g)) //寻找不包含于s的最小值 g++; return mem[w][h] = g; } int main() { int w, h; cout << "纸的宽度 w = "; cin >> w; cout << "纸的高度 h = "; cin >> h; memset(mem, -1, sizeof(mem)); int result = grundy(w, h); if(result) cout << "WIN" << endl; else cout << "LOSE" << endl; return 0; }
相关文章推荐
- 小书账本1:完成记录
- [置顶] linux shell 中的 2>&1 用法说明
- linux shell 中的 2>&1 用法说明
- 传感器之热释电红外传感器
- 报到博客_2016年4月4日
- 【Android学习笔记】ListView使用SimpleAdapter适配器
- java 邮箱验证激活
- JAVA之线程同步的三种方法
- wahaha
- 求最大值和次大值
- 程序core dump了要记得保留现场
- hdu1200(模拟)
- 云模型及其运用
- Android系统应用导入Eclipse中开发
- leetcode之reverse Integer
- C++ 赋值运算符=重载
- [经验]你想不到的PhpExcel导不出文件的原因
- hello world
- LeetCode之旅(20)-Power of Three
- USACO 1.1-beads