Hdu2177-博弈(Sg函数找规律)
来源:互联网 发布:php支付宝当面付demo 编辑:程序博客网 时间:2024/05/17 21:58
收获:一开始wa了,然后进行调试时,调试到某个位置,查看d数组时,codeblock就卡死了,运行程序也关不掉,任务管理器也不起作用,然后逗逼的注销了两次电脑,最后发现,原来数组有一个数组越界了,并且占用了d数组的内存空间,然后就卡死了。
用SG函数进行打表,打出必输的状态:
1 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 0
0 0 0 0 0 0 0 1 0 0
0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
第一个单元是(0, 0),1代表必输。
分别为:
0 0
1 2
2 1
3 5
4 7
5 3
6 10
7 4
8 13
9 15
10 6
11 18
发现差值按0….n增加(先把对称的去掉)。
代码如下:
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;//const int N=1e2+5;//int Sg[N][N];//void init(){// memset(Sg, -1, sizeof(Sg));//}////int SG(int a, int b){// if(~Sg[a][b]){// return Sg[a][b];// }// int used[101]={0};// for(int i=0; i<a; ++i){// used[SG(i, b)]=1;// }// for(int i=0; i<b; ++i){// used[SG(a, i)]=1;// }// for(int i=1; i<=a&&i<=b; ++i){// used[SG(a-i, b-i)]=1;// }// for(int i=0; i<101; ++i){// if(!used[i]) return Sg[a][b]=i;// }//}//////int main(){// init();// int n=20;// Sg[0][0]=0;// for(int i=0; i<n; ++i){// for(int j=0; j<n; ++j){//// printf("%d ", SG(i, j)==0);// if(SG(i, j)==0){// printf("%d %d ", i, j);// }// }// puts("");// }//}const int N=1e6+10;int mp[N<<1], d[N<<1];void init(){ int cur=0; for(int i=0; i<N; ++i){ if(!mp[i]){ mp[i]=i+cur; mp[i+cur]=i; d[cur++]=i; } }}int main(){ int a, b; init(); while(~scanf("%d%d", &a, &b) && (a||b)){ int ansa, ansb; if(a>b){ swap(a, b); } int tmp=b-a; if(d[tmp]>=a&&mp[a]>=b&&mp[b]>=a){ printf("0\n"); continue; } puts("1"); if(d[tmp]<a){ printf("%d %d\n", d[tmp], mp[d[tmp]]); } if(mp[a]>=b&&mp[b]>=a) continue; if(mp[a]<b){ ansa=a; ansb=mp[a]; }else if(mp[b]<a){ ansa=mp[b]; ansb=b; } if(ansa>ansb){ swap(ansa, ansb); printf("%d %d\n", ansa, ansb); } } return 0;}
0 0
- Hdu2177-博弈(Sg函数找规律)
- hdu 1079 Calendar Game(博弈SG函数 || 奇偶找规律)
- codefoeces 603C (博弈 SG函数找规律)
- HDU 5795 A Simple Nim (找规律+sg函数+博弈)
- hdu 1079 Calendar Game (SG函数)(博弈——找规律)
- 51nod 1661 黑板上的游戏(博弈sg函数找规律)
- HDOJ 1851 A Simple Game 博弈 SG函数中找规律
- HDU 1847-Good Luck in CET-4 Everybody!(博弈-SG函数/找规律)
- Again Stone Game (通过SG函数找规律)
- HDU 2311-Nim or not Nim?(Nim博弈-打sg表找规律)
- hdu3951(博弈)找规律
- poj2425(博弈SG函数)
- poj3537(博弈SG函数)
- HDU 2897-邂逅明下(博弈-SG函数打表找规律)
- HDU-5795-A Simple Nim-博弈(SG函数)打表找规律
- 【博弈+SG函数+打表找规律】HDU_5795_A Simple Nim
- 51nod 1067 Hash游戏V2(SG函数找规律)
- HDU 2147kiki's game(SG函数,找规律)
- JavaScript动态实现倒计时
- 广播实践部分——实现强制下线功能
- 继承的概述以及使用方法代码展示以及继承中构造方法的使用
- 省电续航-省电技术
- typedef enum
- Hdu2177-博弈(Sg函数找规律)
- ECNU_OJ_1000
- eclipse的设置
- 抓包
- Codeforces 633H. Fibonacci-ish II (Mo's Algorithm(莫队算法) + 线段树 + 离散化)
- Android中通过Tag为View保存数据绑定数据
- [leetcode 309]Best Time to Buy and Sell Stock with Cooldown--买卖股票with冷却期(DP法)
- iconv转换文件编码
- UIPopover 的简单用法