AtCoder Beginner Contestの過去問から、その提出コードの解答例です。
AtCoderとは、コンテストを通じて、プログラミングやアルゴリズムを学習するサービスです。
atcoder.jp
プログラミングコンテストとは、「与えられた問題をいかに素早く、正確に」解くことができるかを競うものです。
「競技プログラミング」を略して、「競プロ」などと呼ばれています。
#C - 倍々ゲーム
atcoder.jp
僕が作成、提出したコードは、以下のとおりです。
/* AtCoder Problems in C++ #C - 倍々ゲーム https://atcoder.jp/contests/abc027/tasks/abc027_c 提出コードの解答例 https://neguse-atama.hatenablog.com */ #include<bits/stdc++.h> using namespace std; using ll=long long; int main(void){ ll n; cin>>n; int d=0; for(ll i=n;i>0;i/=2){ ++d; } ll x=1; bool p=true; while(1){ if(p){ if(d%2==0){ x=2*x; }else{ x=2*x+1; } }else{ if(d%2==0){ x=2*x+1; }else{ x=2*x; } } if(x>n){ break; } p=!p; } if(p){ cout<<"Aoki"<<endl; }else{ cout<<"Takahashi"<<endl; } return 0; }
AtCoder Beginner Contestは、オンラインジャッジによるプログラミングコンテストです。
日本語と英語に対応していて、週末ごとに実施されているみたいです。
https://practice.contest.atcoder.jp/tutorial
アカウントを登録すれば、誰でも参加できます。