• hdu 4430二分枚举


    枚举r,二分K就可以了,不过还是需要注意细节,比较数据类型之类的,不然容易错。

    /*
     * hdu4430/win.cpp
     * Created on: 2012-10-26
     * Author    : ben
     */
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <cmath>
    #include <ctime>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    #include <stack>
    #include <string>
    #include <vector>
    #include <deque>
    #include <list>
    #include <functional>
    #include <numeric>
    #include <cctype>
    using namespace std;
    typedef long long LL;
    
    LL judge(LL n, int r, int k) {
        LL sum = 0, t = 1;
        while(r--) {
            t *= k;
            sum += t;
            if(sum > n) {
                return 1;
            }
        }
        if(sum == n || sum == n - 1) {
            return 0;
        }
        if(sum > n) {
            return 1;
        }
        return -1;
    }
    
    int bsearchk(int r, LL n) {
        int low = 1, high = 10000000;
        while(low <= high) {
            int mid = (low + high) / 2;
            LL ret = judge(n, r, mid);
            if(ret > 0) {
                high = mid - 1;
            }else if(ret == 0) {
                return mid;
            }else {
                low = mid + 1;
            }
        }
        return -1;
    }
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
        LL n;
        while(scanf("%I64d", &n) == 1) {
            LL ansrk = n - 1;
            LL ansr = 1, ansk = n - 1;
            for(int r = 2; r <= 70; r++) {
                int k = bsearchk(r, n);
                if(k >= 2) {
                    LL temp = (LL)r * k;
                    if(temp < ansrk) {
                        ansrk = temp;
                        ansr = r;
                        ansk = k;
                    }
                }
            }
            printf("%I64d %I64d\n", ansr, ansk);
        }
        return 0;
    }
  • 相关阅读:
    MFC中实现LISTCRTL控件选中多行进行删除操作
    如何使属性值为“只读”(readonly)的EDIT控件在获取焦点后不显示光标?
    crm 使用stark组件
    ModelForm组件
    自定义admin管理工具(stark组件)
    Django-admin管理工具
    Django-session中间件源码简单分析
    基于角色的权限管理
    ajax参数补充
    datetime模块
  • 原文地址:https://www.cnblogs.com/moonbay/p/2741926.html
Copyright © 2020-2023  润新知