• cogs 942. [東方S3] 比那名居天子


    二次联通门 : cogs 942. [東方S3] 比那名居天子

    /*
        cogs 942. [東方S3] 比那名居天子
        
        二分水题
         
        二分所求区间长度
        判断后缩小范围即可 
    */
    #include <cstring>
    #include <cstdio>
    
    #define Max 1000000
    
    void read (int &now)
    {
        now = 0;
        register char word = getchar ();
        while (word < '0' || word > '9')
            word = getchar ();
        while (word >= '0' && word <= '9')
        {
            now = now * 10 + word - '0';
            word = getchar ();
        }
    }
    
    char line[Max];
    
    int N, K;
    
    bool Judge (int key)
    {
        int Count = 0;
        for (register int i = 0; i < N; i ++)
            if (line[i] == '1')
            {
                i += key - 1;
                Count ++;
                if (Count > K)
                    return false;
            }
        return true;
    }
    
    int main (int argc, char *argv[])
    {
        freopen ("tenshi.in", "r", stdin);
        freopen ("tenshi.out", "w", stdout);
        
        read (N);
        read (K);
        
        scanf ("%s", line);
        
        int pos = 0;
        for (pos = 0; line[pos] == '0'; pos ++);
        if (pos == N)
        {
            putchar ('0');
            return 0;
        }
        
        register int Answer;
        for (register int l = 1, r = (N << 1), Mid; l <= r; )
        {
            Mid = l + r >> 1;
            if (Judge (Mid))
            {
                r = Mid - 1;
                Answer = Mid;
            }
            else 
                l = Mid + 1;
        }
        
        printf ("%d", Answer);
        return 0;
    }
  • 相关阅读:
    第七次
    第六次作业
    第五次作业
    第四次作业
    百度网盘生成二维码api
    【css3】--四种气泡
    纯CSS气泡框实现方法探究
    三种带箭头提示框总结实例
    纯CSS实现气泡框
    Windows 上 GitHub Desktop 的操作
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/7163081.html
Copyright © 2020-2023  润新知