---恢复内容开始---
题意:
有n个犯人,手上都有个长度为Li的武器,当铃响时大家同时挥动武器,只能把前面攻击范围内的敌人杀死,问最后还剩几个人。
题目传送门:
[http://codeforces.com/contest/892/problem/B]
思路:
从后面遍历能杀的人,一个一个杀,更新当前能杀的最大人数,用sum统计,最后输出n-sum即可。
代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n,i;
int a[1000005];
while(cin>>n){
for(i=1;i<=n;i++)cin>>a[i];
int sum=0,can=a[n];
for(i=n-1;i>0;i--){
if(can)
sum++;
can--;
can=max(can,a[i]);
}
cout<<n-sum<<endl;
}
return 0;
}