Files
lanqiao/13lanqiao/test10.cpp
2025-04-02 19:50:42 +08:00

27 lines
820 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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
*/