P5720 【深基4.例4】一尺之棰 题解

小邱

2021-02-12 23:12:20

Personal

这道题其实挺简单的,但是要注意有一个坑点,就是从第2天开始 [题目传送门](https://www.luogu.com.cn/problem/P5720) 上代码! ```cpp #include<iostream> using namespace std; int main() { int a,tian=1;//从第2天开始算,所以初值为1 cin>>a; while(a>1) { tian++; a/=2;//由于是整数,自动向下取整了,不需要考虑特殊情况 } cout<<tian; return 0; } ``` [AC记录(c++)](https://www.luogu.com.cn/record/46529410) 只有c++代码总感觉不过瘾,上Py! 注释不加了,和c++一样 ```python a=int(input()) ans=1 while a>1: a//=2 ans+=1 print(ans) ``` [AC记录(python)](https://www.luogu.com.cn/record/46529529)