Codeforces Round #256 (Div. 2) D. Multiplication Table(二进制搜索)
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
----------------------------------------------------------------------------------------------------------------------------------------------------------
1 second
256 megabytes
standard input
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.
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).
Print the k-th largest number in a n × m multiplication
table.
2 2 2
2
2 3 4
3
1 10 5
5
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(二进制搜索)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #256 (Div. 2) D. Multiplication Table
主题链接:http://codeforces.com/contest/448/problem/D 思路:用二分法 code: #include<cstdio> #include<cm ...
- 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 ...
- 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 ...
- Codeforces Round #256 (Div. 2) 题解
Problem A: A. Rewards time limit per test 1 second memory limit per test 256 megabytes input standar ...
- Codeforces Round #256 (Div. 2)
A - Rewards 水题,把a累加,然后向上取整(double)a/5,把b累加,然后向上取整(double)b/10,然后判断a+b是不是大于n即可 #include <iostream& ...
- Codeforces Round #256 (Div. 2) Multiplication Table
C题, #include<cstdio> #include<cstring> #include<algorithm> #define maxn 5005 using ...
- Codeforces Round #256 (Div. 2)——Multiplication Table
题目链接 题意: n*m的一个乘法表,从小到大排序后,输出第k个数 (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m) 分析: 对于k之前的数,排名小于k:k之后的数大于,那么就能够採用 ...
随机推荐
- 3xian退役贴【深思。】
这是原文: 最后一天,漫天飘起了雪花,假装欢送我离去. 这次WF之战不太顺利,早期的C题大概花了1秒钟构思,然而由于输出格式多了一个空格直到两个半小时才逃脱Wrong Answer的纠缠.还好lynn ...
- 【从cocos2d-x学习设计模式】第一阶段:辛格尔顿
设计模式,它总结了前辈在许多方案重用代码.它是一个想法. 因为我们爱cocos2d-x,然后我们从去cocos2d-x在设计模式中,右一起学习!本篇解释未来辛格尔顿. 提cocos2d-x中间Dire ...
- Jetty开发指导:HTTP Client
介绍 Jetty HTTP client模块提供易用的API.工具类和一个高性能.异步的实现来运行HTTP和HTTPS请求. Jetty HTTP client模块要求Java版本号1.7或者更高,J ...
- 使用gdb调试游戏服务器
前言 谈论gdb重要性 一般来说.提gdb,命令用于调试."命令",用户是几乎相同的复杂话.而事实确实如此,实际的开发调试必须用到gdb. 如今.大多数Linux系统是存在于ser ...
- 用"池"来提升对象的复用
对象池化是目前常用的一种系统优化的技术.通俗的说也就是一个对象不用多次的被实例化,来消耗性能,可以把这些常用的类放入一个池中,当需要的时候在去池里去拿去,不用的时候 在放入池中.可以叫做对象池.他可以 ...
- html中加入超链接方式的汇总
在CSS样式中,对超链接的样式有以下几种定义(1)设置链接未被访问时的样式,具体写法如下:a:link{font-size:10px;... }(2)设置链接在鼠标经过时的样式,具体写法如下:a:ho ...
- RSA加密前言
RSA:非对称加密,近期因为工作需要需要实现了一个RSA加密方案.查阅文档无数,主要是通过看他们代码及其引用他人的代码基本实现了跨平台的RSA方案.现在唯一的缺陷是加解密花费的时间太多,下周会把加解密 ...
- Facial Landmark Detection
源地址:http://www.learnopencv.com/facial-landmark-detection/#comment-2471797375 OCTOBER 18, 2015 BY SAT ...
- UpdataData
MFC中有一个UpdataData函数,有二个参数:TRUE和FLASE,二个参数什么时候用, 开始的时候我也迷糊,后来才发现: UpdataData(TRUE):是把控件上的值刷新到变量中: Upd ...
- ORACLE常用数据库类型(转)
oracle常用数据类型 1.Char 定长格式字符串,在数据库中存储时不足位数填补空格,它的声明方式如下CHAR(L),L为字符串长度,缺省为1,作为变量最大32767个字符,作为数据存储在ORAC ...