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

时间:2022-12-17 08:24:55
转载请注明出处:

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



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


----------------------------------------------------------------------------------------------------------------------------------------------------------
欢迎光临天资小屋Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)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 &num;256 &lpar;Div&period; 2&rpar; D&period; Multiplication Table 二分法

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

  2. Codeforces Round &num;256 &lpar;Div&period; 2&rpar; D&period; Multiplication Table 很有想法的一个二分

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

  3. Codeforces Round &num;256 &lpar;Div&period; 2&rpar; D&period; Multiplication Table

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

  4. Codeforces Codeforces Round &num;319 &lpar;Div&period; 2&rpar; A&period; Multiplication Table 水题

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

  5. Codeforces Round &num;256 &lpar;Div&period; 2&rpar; C&period; Painting Fence 或搜索DP

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

  6. Codeforces Round &num;256 &lpar;Div&period; 2&rpar; 题解

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

  7. Codeforces Round &num;256 &lpar;Div&period; 2&rpar;

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

  8. Codeforces Round &num;256 &lpar;Div&period; 2&rpar; Multiplication Table

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

  9. Codeforces Round &num;256 &lpar;Div&period; 2&rpar;——Multiplication Table

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

随机推荐

  1. 做中学(Learning by Doing)之背单词-扇贝网推荐

    做中学(Learning by Doing)之背单词-扇贝网推荐 看完杨贵福老师(博客,知乎专栏,豆瓣)的「继续背单词,8个月过去了」,我就有写这篇文章的冲动了,杨老师说: 有时候我会感觉非常后悔,如 ...

  2. Pro HTML5 Programming&lpar;Second Edition&rpar;2&period;Canvas API(2)

    1.在页面中加入canvas元素 eg: <!DOCTYPE html> <html lang="en"> <head> <meta ch ...

  3. Unicode文件读取 出现隐藏字符 &lpar;大坑&rpar;

    C#读取文件..分析时发现应该15位的.. str.Lenght 却 16位.. 字符串复制出来一位位的数..就是15位.. 纳闷中突然想起来会不会是隐藏字符.. 输出 str[0].ToBytes( ...

  4. C&plus;&plus;与零值比较

    1.布尔值与零值的比较 if(flag)//if为真 if(!flag)//if为假 其它都为不良风格: if (flag == TRUE) ) if (flag == FALSE) ) 2.整形值与 ...

  5. Checklist For Choosing The Right Database Engine

    http://sqlite.org/whentouse.html Appropriate Uses For SQLite SQLite is not directly comparable to cl ...

  6. sematext

    https://sematext.atlassian.net/wiki/display/PUBLOGSENE/Syslog

  7. php实现手机拍照上传头像功能

    现在手机拍照很火,那么如何使用手机拍照并上传头像呢?原因很简单,就是数据传递,首先手机传递照片信息,这个就不是post传递 也不是get函数传递, 这个另外一种数据格式传递,使用的是$GLOBALS ...

  8. Android开发app如何设定应用图标下的应用名称为汉字以及自定义图标

    一.应用名称为汉字 二.自定义图标

  9. EmEditor编辑器正则表达式的优点

    (1)^[ \t]*\n这个正则表达式代表所有的空行,指含有零个或零个以上空格或制表符.以换行符结尾.不含其它字符的行.(2)(^|(?<=中国)).*?(?=中国|$)用正则表达式匹配特定字符 ...

  10. JAVA基础复习与总结&lt&semi;一&gt&semi; 对象与类的概念&lowbar;内部类&lowbar;继承与多态

    一.对象与类 类:类是一个模版,它描述了一类对象的行为和状态. class animal { private int color; private int size; public void eat ...