牛客小白月赛16 小石的签到题(博弈)
生活随笔
收集整理的這篇文章主要介紹了
牛客小白月赛16 小石的签到题(博弈)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
牛客小白月賽16
小石的簽到題
鏈接:https://ac.nowcoder.com/acm/contest/949/A來源:牛客網
題目描述
輸入描述:
共一行,輸入一個數 nnn 。輸出描述:
共一行,輸出 "Shi" 或 "Yang"(不輸出引號)。示例1
輸入
復制
1輸出
復制
Yang說明
小石只能取走 111,小陽贏。示例2
輸入
復制
2輸出
復制
Shi說明
若小石取走 111,則小陽只能取走 222,小石贏。備注:
1≤n≤1091 \leq n \leq 10^91≤n≤109思路:
當 x>1 時,一定先手必贏。
證明:
假設當x>1 時,先手一開始取任意x必輸。
我們知道無論第一次取1~n中的哪個數,1這個數一定被取走。
如果先手選1,后手再選任意x,相當于先手直接選x的狀態(剛剛假設的必輸狀態)
所以假設不成立,
即
? 當 x>1 時,一定先手必贏。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #include <iomanip> #define ALL(x) (x).begin(), (x).end() #define sz(a) int(a.size()) #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long long ,long long> #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define MS0(X) memset((X), 0, sizeof((X))) #define MSC0(X) memset((X), '\0', sizeof((X))) #define pb push_back #define mp make_pair #define fi first #define se second #define eps 1e-6 #define gg(x) getInt(&x) #define chu(x) cout<<"["<<#x<<" "<<(x)<<"]"<<endl #define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c)) #define du2(a,b) scanf("%d %d",&(a),&(b)) #define du1(a) scanf("%d",&(a)); using namespace std; typedef long long ll; ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} ll powmod(ll a, ll b, ll MOD) {a %= MOD; if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;} void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}} void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}inline void getInt(int* p); const int maxn = 1000010; const int inf = 0x3f3f3f3f; /*** TEMPLATE CODE * * STARTS HERE ***/ ll n;int main() {//freopen("D:\\code\\text\\input.txt","r",stdin);//freopen("D:\\code\\text\\output.txt","w",stdout);cin>>n;if(n==1){puts("Yang");}else{puts("Shi");}return 0; }inline void getInt(int* p) {char ch;do {ch = getchar();} while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 + ch - '0';}} }轉載于:https://www.cnblogs.com/qieqiemin/p/11618556.html
總結
以上是生活随笔為你收集整理的牛客小白月赛16 小石的签到题(博弈)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Oracle学习笔记:通过种子数据库设置
- 下一篇: python实例31[文件夹清理]