题解分享
题解分享简介
砍竹子(编程题) - 题解
```
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 10;
vector<unordered_set<int>> hs;
int ans;
int n;
signed main(){
cin >> n;
hs.resize(n + 1);
for(int i = 1; i <= n; ++i){
int x;
cin >> x;
while(x > 1){
if(!hs[i-1].count(x)) ++ans;
hs[i].insert(x);
x = sqrt(x / 2 + 1);
}
}
cout << ans << endl;
return 0;
}
```
```
```
查看全文
0
0
0
6
砍竹子(编程题) - 题解
```c++
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
vector<unordered_set <int>> hh; // 无序集记录对每棵竹子操作后得到的高度
int ff(int x) {
return sqrt(x / 2 + 1);
}
signed main()
{
cin >> n;
hh.resize(n + 1);
int ans = 0;
for(int i = 1; i <= n; i ++ ) {
int x;
cin >> x;
while(x > 1) {
if(!hh[i - 1].count(x)) ans ++ ; // 前一棵竹子操作过程中与当前竹子此时高度相同可以一起
hh[i].insert(x); // 将当前竹子高度记录
x = ff(x); // 砍竹子
}
}
cout << ans;
}
```
查看全文
0
0
0
2



