Cod sursa(job #2076266)

Utilizator pionierul22aNa LiZa pionierul22 Data 26 noiembrie 2017 13:10:30
Problema Pod Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin ("pod.in");
ofstream fout ("pod.out");
int n,b,k;
int g[100001];

int solutie(int L)
{
    int st=0,ok=1;
    while(st<=L && ok==1)
    {
        if(g[st+1]==0)
            st++;
        else
            if(g[st+k]==0)
            st=st+k;
        else
            ok=0;
    }
    return ok;
}

int main()
{
    fin>>n>>b>>k;
    for(int i=1;i<=b;i++)
        {
            int c;
            fin>>c;
            g[c]=-1;
        }

    int nr=0,L=n;
    while(L>1)
    {
        if(solutie(L)==1)
            nr++;
        L=L/2;
    }
    fout<<nr;
    return 0;
}