lanqiao 2117 砍竹子

This commit is contained in:
2025-04-02 19:50:42 +08:00
parent e2e5296a66
commit f7aad2ae6a

27
13lanqiao/test10.cpp Normal file
View File

@@ -0,0 +1,27 @@
// lanqiao 2117 砍竹子
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n; cin >> n;
set<int> pre; // 记录上一次竹子高度变化
int ans = 0;
for(int i = 1; i <= n; i++){
int h; cin >> h;
set<int> cur; // 维护当前竹子的高度变化
while(h != 1){
cur.insert(h);
// 如果上一根竹子高度变化中没有h则需要单独消耗一次操作
// 否则若相邻两根竹子在高度递减过程中存在高度相同的情况,则第二根竹子不需要重新计数,因为两根竹子一起砍就行了
if(!pre.count(h)) ans++;
h = sqrtl(h/2 + 1);
}
pre = cur;
}
cout << ans << endl;
return 0;
}
/* test samples -> 5
6
2 1 4 2 6 7
*/