码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #256 (Div. 2)——Multiplication Table

时间:2014-07-18 12:37:24      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:style   http   color   os   io   for   

题目链接

  • 题意:
    n*m的一个乘法表,从小到大排序后,输出第k个数
     (1?≤?n,?m?≤?5·105; 1?≤?k?≤?n·m)
  • 分析:
    对于k之前的数,排名小于k;k之后的数大于,那么就可以采用二分。
LL n, m, k;

LL fun(LL goal)
{
    LL t = 0, ret = 0;
    while (++t <= m)
    {
        ret += min(n, goal / t);
    }
    return ret;
}

LL bin(LL L, LL R, LL goal)
{
    LL M, V;
    while (L <= R)
    {
        M = (L + R) >> 1;
        V = fun(M);
        if (V < goal)
            L = M + 1;
        else
            R = M - 1;
    }
    return L;
}

int main()
{
//    freopen("in.txt", "r", stdin);
    while (cin >> n >> m >> k)
    {
        cout << bin(1, 1e15, k) << endl;
    }
    return 0;
}


Codeforces Round #256 (Div. 2)——Multiplication Table,布布扣,bubuko.com

Codeforces Round #256 (Div. 2)——Multiplication Table

标签:style   http   color   os   io   for   

原文地址:http://blog.csdn.net/wty__/article/details/37923807

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!