摸了两周python和qq机器人, 回来搞算法了
--------------------------------------------------------------------------------------------------------------------------------
题目链接:Problem - 892B - Codeforces
先录入一遍数据, 然后倒序记录被杀死的人, 同时更新一下当前最长武器长度就好了
时间复杂度O(n)
注意如果O(n2)就会超时(t过一次
ac代码:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <deque>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, b) for (ll i = (a); i <= (b); i++)
#define repr(i, a, b) for (ll i = (a); i < (b); i++)
#define rrep(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepr(i, a, b) for (ll i = (b); i > (a); i--)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
ll cnt,n,m,t,ans,ant;
const int N=1e7+10;
ll arr[N];
ll bo[N];
string str;
inline ll read()
{
char c = getchar();int x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}//是符号
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}//是数字
return x*s;
}
void solve()
{
n=read();
rep(i,1,n)
arr[i]=read();
cnt=arr[n];//刀长
rrep(i,1,n-1)
{
if(cnt)//在武器范围内, 死去的人
ans++;
cnt--;
cnt=max(cnt,arr[i]);
}
cout<<n-ans;
return;
}
int main()
{
solve();
return 0;
}