题目

CF448D Multiplication Table

思路

二分答案。这个矩阵的每一排都是递增的,所以二分\(ans\),去计算有多少个数等于\(ans\),有多少个数小于\(ans\),如果小于\(ans\)的数不多于\(k-1\)个并且小于等于\(ans\)的数不少于\(k\)个,那么当前\(ans\)就是答案。

Q:如何计算小于\(ans\)的数的个数?

A:

\[\sum_{i=1}^{n}min(\lfloor \frac{ans-1}{i} \rfloor,m)
\]

Q:如何计算等于\(ans\)的数的个数?

A:当\(i|ans\)并且\(ans/i\)小于\(m\)时个数加一。

\(Code\)

#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
#define ll long long
using namespace std;
ll n,m,k;
inline void read(ll &T){
ll x=0;bool f=0;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=!f;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
T=f?-x:x;
}
inline void write(ll x){
if(x<0) putchar('-'),write(-x);
else{
if(x/10) write(x/10);
putchar(x%10+'0');
}
} int main(){
read(n),read(m),read(k);
ll l=1,r=n*m;
while(l<=r){
ll mid=(l+r)>>1,sum=0,tmp=0;
for(int i=1;i<=n;++i){
sum+=min((mid-1)/i,m);
if(mid%i==0&&mid/i<=m) tmp++;
}
if(sum<=k-1&&sum+tmp>=k){
write(mid);
return 0;
}
if(sum+tmp<=k-1) l=mid+1;
else r=mid-1;
}
return 0;
}

洛谷 CF448D Multiplication Table的更多相关文章

  1. cf448D Multiplication Table

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

  2. cf448D Multiplication Table 二分

    题目:http://codeforces.com/problemset/problem/448/D 题意:给出n,m,k,即在一个n*m的二维数组中找第k大的数,第i行第j列的数的值为i*j. 思路: ...

  3. 洛谷 P5089: CodeForces #500 (Div. 1) B / 1012B : Chemical table

    题目传送门:洛谷P5089. 题意简述: 一张 \(n \times m\) 的表格,有一些格子有标记,另外一些格子没有标记. 如果 \((r_1,c_1),(r_1,c_2),(r_2,c_1)\) ...

  4. 洛谷 [USACO17OPEN]Bovine Genomics G奶牛基因组(金) ———— 1道骗人的二分+trie树(其实是差分算法)

    题目 :Bovine Genomics G奶牛基因组 传送门: 洛谷P3667 题目描述 Farmer John owns NN cows with spots and NN cows without ...

  5. 洛谷 P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat…(树规)

    题目描述 Bessie is planning the annual Great Cow Gathering for cows all across the country and, of cours ...

  6. uva A Spy in the Metro(洛谷 P2583 地铁间谍)

    A Spy in the Metro Secret agent Maria was sent to Algorithms City to carry out an especially dangero ...

  7. 纪中23日c组T2 2159. 【2017.7.11普及】max 洛谷P1249 最大乘积

    纪中2159. max 洛谷P1249 最大乘积 说明:这两题基本完全相同,故放在一起写题解 纪中2159. max (File IO): input:max.in output:max.out 时间 ...

  8. 洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 使用四种算法

    洛谷P1218 [USACO1.5]特殊的质数肋骨 Superprime Rib 水题一道…… 题目描述 农民约翰的母牛总是产生最好的肋骨.你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. ...

  9. [洛谷日报#204] StackEdit——Markdown 编辑器的功能介绍

    本文同时发表于洛谷日报,您也可以通过洛谷博客进行查看. 1.介绍与开始使用 1.1 这是什么? StackEdit是基于PageDown.Stack Overflow和其他堆栈交换站点使用的Markd ...

随机推荐

  1. ssm(spring+springmvc+mybatis)整合之环境配置

    1-1.导包 导入SpringMVC.Spring.MyBatis.mybatis-spring.mysql.druid.json.上传和下载.验证的包 1-2.创建并配置web.xml文件 配置sp ...

  2. Java自学-控制流程 switch

    Java的 switch 语句 switch 语句相当于 if else 的另一种表达方式 示例 1 : switch switch可以使用byte,short,int,char,String,enu ...

  3. Mock、Powermock使用汇总

    背景 工作中经常用到单测,某对单测掌握的不好,所以趁此学习.总结一下. 主要参考:https://www.jianshu.com/p/0c2480b1709e.https://www.cnblogs. ...

  4. localStorage&sessionStorage&Cookie

    localStorage.sessionStorage.Cookie三者区别如下:

  5. exchange From Middle English eschaunge

    exchange From Middle English eschaunge, borrowed from Anglo-Norman eschaunge exchange 1.An act of ex ...

  6. np.random模块的使用介绍

    np.random模块常用的一些方法介绍 名称 作用 numpy.random.rand(d0, d1, …, dn) 生成一个[d0, d1, …, dn]维的numpy数组,数组的元素取自[0, ...

  7. scrapy 下载器中间件 随机切换user-agent

    下载器中间件如下列表 ['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware', 'scrapy.downloadermiddlewa ...

  8. robotframe添加自定义lib 报Importing test library ‘xxxx’ failed

    问题现象:在linux服务器上搭建jenkins 执行robot工程时报:Importing test library  ‘xxxx’   failed 问题分析一: 在library  引入非rob ...

  9. 转:ajax的AntiForgery和Authorize 以及ajax登录例子

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/ashcn2001/article/det ...

  10. Upgrade Windows Server 2016 to Windows Server 2019

    Pre-Upgrade Upgrade path: Windows Server 2016 can be upgraded to Windows 2019 in a single upgrade pr ...