二分法判断答案

D. Multiplication Table
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Bizon the Champion isn't just charming, he also is very smart.

While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted ann × m multiplication
table, where the element on the intersection of the i-th row and j-th
column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th
largest number?

Bizon the Champion always answered correctly and immediately. Can you repeat his success?

Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th
number you write out is called the k-th largest number.

Input

The single line contains integers nm and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).

Output

Print the k-th largest number in a n × m multiplication
table.

Sample test(s)
input
2 2 2
output
2
input
2 3 4
output
3
input
1 10 5
output
5
Note

A 2 × 3 multiplication table looks like this:

1 2 3
2 4 6

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map> using namespace std; typedef long long int LL; LL n,m,k; bool ck(LL x)
{
LL nt=0;
for(LL i=1;i<=n;i++)
{
nt+=min(m,x/i);
}
if(nt>=k) return true;
return false;
} int main()
{
scanf("%I64d%I64d%I64d",&n,&m,&k); LL low=1,high=n*m,ans=-1,mid;
while(low<=high)
{
mid=(low+high)/2;
if(ck(mid))
{
ans=mid; high=mid-1;
}
else low=mid+1;
}
printf("%I64d\n",ans); return 0;
}

版权声明:来自: 代码代码猿猿AC路 http://blog.csdn.net/ck_boss

Codeforces 448 D. Multiplication Table的更多相关文章

  1. Codeforces 448 D. Multiplication Table 二分

    题目链接:D. Multiplication Table 题意: 给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m). 题解: n ...

  2. Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  3. Codeforces Codeforces Round #319 (Div. 2) A. Multiplication Table 水题

    A. Multiplication Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/57 ...

  4. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table

    链接: https://codeforces.com/contest/1220/problem/B 题意: Sasha grew up and went to first grade. To cele ...

  5. Codeforces Round #256 (Div. 2) D. Multiplication Table 二分法

     D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input st ...

  6. Codeforces Round #256 (Div. 2) D. Multiplication Table 很有想法的一个二分

    D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input stand ...

  7. Day8 - D - Multiplication Table CodeForces - 448D

    Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the mu ...

  8. CodeForces 448

    A:Rewards: 题目链接:http://codeforces.com/problemset/problem/448/A 题意:Bizon有a1个一等奖奖杯,a2个二等奖奖杯,a3个三等奖奖杯,b ...

  9. hdu4951 Multiplication table (乘法表的奥秘)

    http://acm.hdu.edu.cn/showproblem.php?pid=4951 2014多校 第八题 1008 2014 Multi-University Training Contes ...

随机推荐

  1. GPS 偏移校正(WGS-84) 至(GCJ-02) java版本号以实现

    public class EvilTransform { final static double pi = 3.14159265358979324; // // // a = 6378245.0, 1 ...

  2. JAVA程序生成XML标准化的文件格式,缩进,美化。

    //他开始Document映射到文件 TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer t ...

  3. 配置Tomcat的日志系统

    成功配置tomcat的log4j日志系统,格式:HTML+每天以yyyy-mm-dd.log命名的日志文件 一.引言: 实习单位让用log4j配置webapp的日志系统,要求产生的日志文件是html格 ...

  4. 解决android3.0版本号以上应用接收不到开机广播问题

    如今是2014-07-16 下午15:27. 好久没写过东西,突然间灵感喷发想写点东西(事实上是刚刚弄好了一个棘手的问题,自豪中..呵呵呵呵 我牛掰).废话不多说,进入正题. 不知道你们又没有碰到这问 ...

  5. BootStrap -- Grid System

    <script src="jquery.1.9.js"></script> <script src="js/bootstrap.min.js ...

  6. Eclipse正确导入第三方project

    前言 昨晚,在不同的Android做出最终的在线测试时间,在其他平台上正常升级的提示突然报告出来"java.lang.NoClassDefFoundError"误.拉什adb lo ...

  7. hdu2993坡dp+二进制搜索

    MAX Average Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  8. Spring3.2 HelloWorld

    直接上图吧: jar包: 项目文件夹一览: 这里的HelloWeb-servlet,xml 是在WEB-INF 下 HelloController: package com.cqu.tutorial; ...

  9. poj 2288 Islands and Bridges

    题意: 给你一个双向连通图,求 获得权值最大 的 哈密顿通路的 权值 和 这个权值对应的数目: 其中权值计算方法是  列如 ABCD  权值是a+b+c+d+ab+bc+cd 如果 A,B,C  和B ...

  10. Simple Automated Backups for MongoDB Replica Sets

    There are a bunch of different methods you can use to back up your MongoDB data, but if you want to ...