转载请注明出处:

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. 回文(manacher)

    裸manacher 我竟然写跪了………… 一个地方(偶数)没写清楚…… 我OOXOXOXOXXOXO #include<cstdio> #include<cstdlib> #i ...

  2. javascript学习初衷

    很久没有过来写东西了,由于要做小网页,介于不懂javascript,一味的去爬其他站点的代码下来,却不能自由组合,控制,达到自己想要的效果, 于是只能沉下心,javascript从头学起,还记得张老师 ...

  3. 研读asp.net排课功能实现学习笔记

    1.datatable.select 方法,返回的是一个datarow数组 DataRow[] drs =                    dtHBKC.Select("Subject ...

  4. 八皇后问题详细分析与解答(递归法解答,c#语言描述)

    八皇后问题,是一个古老而著名的问题,是回溯算法的典型例题.该问题是十九世纪著名的数学家高斯1850年提出:在8X8格的国际象棋上摆放八个皇后,使其不能互相攻击,即任意两个皇后都不能处于同一行.同一列或 ...

  5. UNIX下改动时间简单一例

    UNIX下改动时间简单一例 仅仅输入date就显示当前的工作站时间,假设有root超级用户权限,加上參数能够改动 工作站的时间. 格式:date mmddHHMM[cc]yy mm--月份,dd--日 ...

  6. [Windows Phone学习笔记]UserControl的使用

    UserControl的使用 开发过程中,多个UI控件需要协同工作,相互交互之后,才可完成一个完整的业务需求,此时可把这些控件封装成为一个整体,相互之间的交互逻辑封装其中,外部调用可无需关心内部逻辑, ...

  7. fragment Trying to instantiate a class com.example.testhuanxindemo.MyFragment that is not a Fragmen

    在使用fragment的时候,先创建了一个fragment,然后为他创建布局,并在oncreateview中返回载入该视图的后返回的view,在activity的布局文件里,使用xml布局,用frag ...

  8. a++为啥不能用作左值

    原地址:http://wy892648414.blog.163.com/blog/static/212212135201378496591/ 1)首先说左值和右值的定义: 变量和文字常量都有存储区,并 ...

  9. Cocos2d-x-lua游戏两个场景互相切换MainScene01切换到MainScene02

    /* 场景一lua代码 */ require "MainScene02" local dic_size = CCDirector:sharedDirector():getWinSi ...

  10. 流动python - 字符串KMP匹配

    首先我们看一下简单的字符串匹配. 你可以把文本字符串s固定,模式字符串p从s对齐的左边缘,作为承担部分完全一致,匹配成功,失败将是模式字符串p整体向右1地点,继续检查对齐部分,重复. #朴素匹配 de ...