公式
A - Exponential Plant 解説
by
A - Exponential Plant 解説
by
MtSaka
初心者の方へ
- プログラミングの学習を始めたばかりで何から手をつけるべきかわからない方は、まずは practice contest の問題A「Welcome to AtCoder」をお試しください。言語ごとに解答例が掲載されています。
- また、プログラミングコンテストの問題に慣れていない方は、 AtCoder Beginners Selection の問題をいくつか試すことをおすすめします。
- C++入門 AtCoder Programming Guide for beginners (APG4b) は、競技プログラミングのための C++ 入門用コンテンツです。
while文などを用いて植物の高さが高橋君より高くなるまで、一日ごとに伸びた高さを足していくシミュレーションすることで答えを求めることができます。
また、30日目には植物の高さは \(1073741823\, \mathrm{cm}(> 10^{9}\, \mathrm{cm})\) となっているため、while文で1日ごとに高さを求めていく方法で十分高速に求まります。
実装例(C++):
#include <bits/stdc++.h>
using namespace std;
int main(){
int h;
cin >> h;
int ans = 0;
int now = 0;
while (now <= h) {
now += 1 << ans;
ans++;
}
cout << ans << endl;
}
実装例(Python):
h=int(input())
now=0
ans=0
while now<=h:
now+=1<<ans
ans+=1
print(ans)
投稿日時:
最終更新: