转载请注明出处:

viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmode=contents

题目链接:http://codeforces.com/contest/448/problem/D



----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋http://user.qzone.qq.com/593830943/main

----------------------------------------------------------------------------------------------------------------------------------------------------------

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

题目意思是,从一个n*m的乘法表(不要问我乘法表是什么)中选出第k小数(同样的数字会计算多次)。

比方例子 2 3 4

乘法表为

1 2 3

2 3 4

非减序列是:1, 2, 2, 3, 3, 4。第4个数字是3。所以输出3。

代码例如以下:

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
LL n, m, k;
LL min(LL a, LL b)
{
return a<b? a:b;
}
LL check(LL x)//查找比x小的个数
{
LL num = 0;
for(int i = 1; i <= n; i++)
{
num+=min(m,x/i);
}
if(num >= k)
return 1;
else
return 0;
}
int main()
{
while(cin>>n>>m>>k)
{
LL l = 0, r = n*m, ans = 0;
while(l <= r)
{
LL mid = (l+r)>>1;
if(check(mid))
{
ans = mid;
r = mid-1;
}
else
l = mid+1;
}
cout<<ans<<endl;
}
return 0;
}

Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. Codeforces Round #256 (Div. 2) D. Multiplication Table

    主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...

  4. 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 ...

  5. Codeforces Round #256 (Div. 2) C. Painting Fence 或搜索DP

    C. Painting Fence time limit per test 1 second memory limit per test 512 megabytes input standard in ...

  6. Codeforces Round #256 (Div. 2) 题解

    Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...

  7. Codeforces Round #256 (Div. 2)

    A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...

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

    C题, #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5005 using ...

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

    题目链接 题意: n*m的一个乘法表,从小到大排序后,输出第k个数  (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m) 分析: 对于k之前的数,排名小于k:k之后的数大于,那么就能够採用 ...

随机推荐

  1. Spring MVC集成Tiles使用方法

    首先,我们定义一个总体的tiles视图 /tiles/mainTemplate.jsp首先使用:<tiles:getAsString name="title"/>打印t ...

  2. Greenplum同步到Oracle

    开发提出须要从Greenplum同步到Oracle的解决方式,写了个脚本用于定时调度处理. #!/bin/sh #copy_gp_2_ora.sh if [ $# -ne 1 ]; then     ...

  3. ExtJs4 笔记(9) Ext.Panel 面板控件、 Ext.window.Window 窗口控件、 Ext.container.Viewport 布局控件

    本篇讲解三个容器类控件. 一.面板控件 Ext.Panel 一个面板控件包括几个部分,有标题栏.工具栏.正文.按钮区.标题栏位于最上面,工具栏可以在四个位置放置,围绕中间部分正文,按钮区位于最小方.下 ...

  4. [破解]java打包Exe工具 - Jar2Exe Wizard

    打包java文件为exe的方法和软件有很多,还有一些开源的软件和一些免费的软件. 我用过的所有打包exe软件中,Jar2Exe Wizard是最好用的,但是只有一个月的试用期,需要的可以从官网下载. ...

  5. svn强制用户提交时写日志

    #!/bin/sh REPOS="$1" TXN="$2" SVNLOOK=/usr/bin/svnlook #根据你的SVN目录而定 LOGMSG=`$SVN ...

  6. 14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚

    14.3.2.2 autocommit, Commit, and Rollback 自动提交 提交和回滚 如果自动提交模式被启用,在InnoDB里, 所有的用户活动发生在一个事务里, 每个SQL语句 ...

  7. SilkTest Q&A 3

    Q21:如何给testcase的属性赋值? A21: 1.确定你的testplan处于打开状态. 2.点击你准备赋属性值的testcase 3.点击TestPlan/detail菜单,testplan ...

  8. 获取Jenkins project build结果

    当Jenkins管理的build project越来越多的时候,须要脚本收集每一个project的近期一次build结果,从而集中管理.依据业务规则,决定是否重算和何时重算. 以下的命令是利用curl ...

  9. hdu 3405 world islands

    求删点后最小的生成树,n<50....数据好弱,直接暴力枚举就行...删点的时候直接g[i][j]=INF就行了. #include<iostream> #include<al ...

  10. 图像特征提取方法:Bag-of-words

    Bag-of-words简单介绍 最初的Bag-of-words ,也叫做"词袋",在信息检索中,Bag-of-words model假定对于一个文本,忽略其词序和语法,句法,将其 ...