标签:out pen its line mes none namespace c++ ||
题目大意
#include<bits/stdc++.h> using namespace std; inline int read() { int sum = 0,p = 1; char ch = getchar(); while(ch < ‘0‘ || ch > ‘9‘) { if(ch == ‘-‘) p = -1; ch = getchar(); } while(ch >= ‘0‘ && ch <= ‘9‘) { (sum *= 10) += ch - ‘0‘; ch = getchar(); } return sum * p; } const int N = 5e5 + 5; int n,ans; struct edge { int l,r; } e[N]; int main() { freopen("cat.in","r",stdin); freopen("cat.out","w",stdout); n = read(); for(int i = 1; i <= n; i++) { int a = read(); e[i].l = max(0,i - a); e[i].r = min(n,i + a); } int far = 0,now = 1,mid; while(now <= n) { far = 0; for(int i = 1;i <= n;i++) { if(e[i].l <= now && e[i].r >= now) if(far < e[i].r) far = e[i].r; } now = far + 1; ans++; } printf("%d\n",ans); return 0; }
标签:out pen its line mes none namespace c++ ||
原文地址:https://www.cnblogs.com/darlingroot/p/11351499.html