C++ 巴什博弈:若 n 为 k+1 的倍数,则先手必败
#include <iostream> using namespace std; int main() { int t, n, m; cin >> t; while (t--) { cin >> n >> m; // n<=m Y // n==m+1 N // n>m+1 n<=2m+1 Y if (n%(m+1)==0) cout << "NO" << endl; else cout << "YES" << endl; } } // 64 位输出请用 printf("%lld")
举一反三:
#include <iostream> using namespace std; int main() { int t, n, l, r; cin >> t; while (t--) { cin >> n >> l >> r; // n<l N // l<=n<=r Y // r+1<=n<=r+l N if (n%(r+l)<=l) cout << "NO" << endl; else cout << "YES" << endl; } } // 64 位输出请用 printf("%lld")