Educational Codeforces Round 45 E. Post Lamps

Posted lhclqslove

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Educational Codeforces Round 45 E. Post Lamps相关的知识,希望对你有一定的参考价值。

题目链接:E. Post Lamps

题解:用一个las数组保存当前位置可以左边包括自己离自己最近的位置,然后暴力求每个不同的灯至少需要多少个然后更新答案

#include<bits/stdc++.h>
#include<set>
#include<cstdio>
#include<iomanip>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#define pb push_back
#define ll long long
#define fi first
#define se second
#define PI 3.14159265
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define eps 1e-7
#define pii pair<int,int>
typedef unsigned long long ull;
const int mod=1e3+5;
const ll inf=0x3f3f3f3f3f3f3f;
const int maxn=1e6+5;
using namespace std;
ll n,m,k,ans=inf;
bool vis[maxn];
int a[maxn],las[maxn];
int main()
{
    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<m;i++)
    {
        int x;
        scanf("%d",&x);vis[x]=true;
    }
    int p=-1;
    for(int i=0;i<n;i++)
    {
        if(!vis[i])
        {
            las[i]=i;p=i;
        }
        else las[i]=p;
    }
    for(int i=1;i<=k;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=k;i++)
    {
        int pos=0,cnt=0;
        while(pos<n)
        {
           if(las[pos]>=0&&las[pos]+i>pos)
           {
               pos=las[pos]+i;cnt++;
           }
           else break;
        }
        if(pos>=n)ans=min(ans,1ll*cnt*a[i]);
    }
    if(ans<inf)
    {
        printf("%lld
",ans);
    }
    else printf("-1
");
}

 

以上是关于Educational Codeforces Round 45 E. Post Lamps的主要内容,如果未能解决你的问题,请参考以下文章

Educational Codeforces Round 7 A

Educational Codeforces Round 7

Educational Codeforces Round 90

Educational Codeforces Round 33

Codeforces Educational Codeforces Round 54 题解

Educational Codeforces Round 27