Codeforces Round #476 (Div. 2) D. Single-use Stones
D. Single-use Stones
Examples 1: input 10 5 0 0 1 0 2 0 0 1 0 output 3 Examples 2: input 10 3 1 1 1 1 2 1 1 1 1 output 3
题意:
w表示河的宽度,l表示青蛙所能跳的最远的距离,第二行的w-1个元素表示离河岸为i的地方有a[i]个石头,一 个石头被踩两次,问最多有多少只青蛙可以跳到河对岸
分析:
因为最多能跳过几只青蛙,是由落脚点的数目的最小值决定的,所以他的问题实际上就是在[i,i+l],i∈[l,w-1], 最少的石头数目是多少
个人代码:
#define debug #include<stdio.h> #include<math.h> #include<cmath> #include<queue> #include<stack> #include<string> #include<cstring> #include<string.h> #include<algorithm> #include<iostream> #include<vector> #include<functional> #include<iomanip> #include<map> #include<set> #define pb push_back #define dbg(x) cout<<#x<<" = "<<(x)<<endl; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll>PLL; typedef pair<int,ll>Pil; const ll INF = 0x3f3f3f3f; const ll inf=0x7fffffff; const double eps=1e-8; const int maxn =1e6; const int N = 510; const ll mod=1e9+7; const ll MOD=1e9; //------ //define ll sum[maxn]; ll a[maxn]; int w,l; //solve void solve() { while(cin>>w>>l){ ll ans=inf; for(int i=1;i<w;i++){ cin>>a[i]; sum[i]=sum[i-1]+a[i]; } for(int i=l;i<=w-1;i++){ ans=min(ans,sum[i]-sum[i-l]); } cout<<ans<<endl; memset(sum,0,sizeof(sum)); } } //main int main() { ios_base::sync_with_stdio(false); #ifdef debug freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif cin.tie(0); cout.tie(0); solve(); /* #ifdef debug fclose(stdin); fclose(stdout); system("out.txt"); #endif */ return 0; }