题目

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. websocket-shap 函数Broadcast的使用方法

    Broadcast:在websocket-shap函数的定义是:向WebSocket服务中的每个客户端发送数据,类似于广播的效果 如果要使用异步发送,可使用BroadcastAsync函数. 在源码中 ...

  2. Spring Security Architecture and Implementation(架构和实现)学习笔记

    Spring Security 关于spring-security的官网文档学习笔记,主要是第8章 Architecture and Implementation(架构和实现)内容 参考: https ...

  3. JavaWeb 之 MVC 开发模式

    MVC 开发模式 一.JSP 演变历史 1. 早期只有servlet,只能使用response输出标签数据,非常麻烦 2. 后来又jsp,简化了Servlet的开发,如果过度使用jsp,在jsp中即写 ...

  4. nginx小结

    1.nginx下部署网站 网站为:http://10.1.75.177:8000 nginx端口为80 配置如下: user nginx; worker_processes auto; error_l ...

  5. 【RAC】 RAC For W2K8R2 安装--dbca创建数据库(七)

    [RAC] RAC For W2K8R2 安装--dbca创建数据库(七) 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可 ...

  6. React: 无状态组件生成真实DOM结点

    在上一篇文章中,我们总结并模拟了 JSX 生成真实 DOM 结点的过程,今天接着来介绍一下无状态组件的生成过程. 先以下面一段简单的代码举例: const Greeting = function ({ ...

  7. Linux_安装maven

    安装maven 1.首先要已经安装JDK 2.下载安装包,可以安装包下: 下载地址:https://mirrors.cnnic.cn/apache/maven/ wget https://mirror ...

  8. C++ STL hash表用法

    C++ STL unordered_map用法 在C++11中,unordered_map作为一种关联容器,替代了hash_map,unordered_map的底层实现是hash表,所以被称为无序关联 ...

  9. Python的元编程案例

    Python的元编程案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.什么是元编程 元编程概念来自LISP和smalltalk. 我们写程序是直接写代码,是否能够用代码来生成 ...

  10. 日常bug(1)

    今天在写写代码的时候,前端找我,说我写的一个接口有可能有问题.导致前端的数据不能正常显示,我去看了一下,确实不能正常显示.问题的原因是本来前端循环遍历一个json里的数组,但是接下来的数据变成对象了. ...