牛牛和牛可乐的赌约2 [sg定理]

牛牛和牛可乐的赌约2

https://ac.nowcoder.com/acm/contest/7412/B

题意

大小的棋盘中,对位置的棋子进行操作,向上1或2格,向左1或2格。最终无法移动棋子的人输。

题解

根据SG定理画出NP点的转移图

SG定理

P点(必胜点):即处于此位置,在双方无失误情况下此方必胜
N点(必败点):即处于此位置,在双方无失误情况下此方必败
转移:
1.对于所有必胜点,一定存在至少一种情况在下一步进入必败点
2.对于所有必败点,在所有情况下的下一步均进入必胜点。

本题的转移图如下:
图片说明

在图中可看到,此图是关于左上-右下对角线对称的,所以只关注左下三角即可。发现当且仅当y与x坐标之差为3的倍数或0时,为必败点。

code

#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

int main()
{
   ios;
   int t;
   cin>>t;
   while(t--){
      ll n,m;
      cin>>n>>m;
      if(n > m) swap(n,m);
      if((m - n) % 3 == 0) puts("awsl");
      else puts("yyds");
   }


   return 0;
}
全部评论
在(0,1)点为什么牛牛能走赢呀?此时牛牛走一步不就到了(0,0)点吗?
点赞 回复 分享
发布于 2020-09-20 11:11

相关推荐

09-01 17:26
已编辑
门头沟学院
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
09-29 11:20
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务