P15034 [UOI 2021 II Stage] 奇迹之地 题解
Zskioaert1106 · · 题解
题目传送门:P15034 [UOI 2021 II Stage] 奇迹之地
题目分析
对于一个数
考虑分析什么时候不能砍。根据上面的分析,在
归纳地,存在不能被砍的
因此只需记录“不能被砍”叠到了多少层。记
:::warning[注意]
若
此外答案要开 long long。
代码实现
#include<iostream>
using namespace std;
int n,x,y=1;
long long ans;
int main(){
cin>>n;
while(n--){
cin>>x;
if(x>y)ans+=x-1,x=1;
if(x==y)y++;
}
cout<<ans;
return 0;
}
AC 记录。