题目链接:D. Multiplication Table

题意:

  给出N×M的乘法矩阵要你求在这个惩罚矩阵中第k个小的元素(1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m).

题解:

  n和m最大都是5e5那矩阵最大就有2e11不能够暴力,其实这里就应该想到要用二分做的,但是我做题的时候脑抽@。@想要推规律,然后就决决了。那么讲一下二分怎么做,就先简单的二分答案在(1-n*m)中二分,然后cheak函数中找所有矩阵中比所给值小的元素,个数大于等于k为成立条件。复杂度(O(n*log(n×m)));

 #include<bits/stdc++.h>
using namespace std;
const int MAX_N = 5e5+;
long long vec[MAX_N];
long long N,M,T;
bool cheak(long long x)
{
long long sum = ;
for(long long i=;i<=N;i++)
{
//cout<<"!!!!!"<<x/i<<endl;
sum += min(x/i,M);
}
if(sum < T)return true;
else return false;
}
int main()
{ while(cin>>N>>M>>T)
{
long long l=,r=N*M;
while(l<=r)
{
long long mid = (l+r)/;
//cout<<"....."<<mid<<endl;
if(cheak(mid))
{
l = mid+;
}
else
{
r = mid-;
}
}
long long ans = l;
cout<<ans<<endl;
}
return ;
}
 

Codeforces 448 D. Multiplication Table 二分的更多相关文章

  1. Codeforces 448 D. Multiplication Table

    二分法判断答案 D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. cf448D Multiplication Table 二分

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

  3. D. Multiplication Table 二分查找

    刚做这道题根本没想到二分,最关键是没想出来怎样统计在这个矩阵中比一个数小的有几个怎么算.造成自己想了好久最后看了别人的提示才做出来.哎.好久不做题太弱了 #include<iostream> ...

  4. 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 ...

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

    转载请注明出处:viewmode=contents" target="_blank">http://blog.csdn.net/u012860063?viewmod ...

  6. 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 ...

  7. 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 ...

  8. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...

  9. Codeforces Round #586 (Div. 1 + Div. 2) B. Multiplication Table

    链接: https://codeforces.com/contest/1220/problem/B 题意: Sasha grew up and went to first grade. To cele ...

随机推荐

  1. Django__WSGI

    WEB应用的本质 : 1. 浏览器发送一个http请求 2. 服务器收到请求,生成一个html文档 3. 服务器把HTML文档作为HTTP响应的body发送给浏览器 4. 浏览器收到http响应,从h ...

  2. 通过WebSocket实现一个简单的聊天室功能

    WebSocket WebSocket是一个协议,它是是基于TCP的一种新的网络协议,TCP协议是一种持续性的协议,和HTTP不同的是,它可以在服务器端主动向客户端推送消息.通过这个协议,可以在建立一 ...

  3. Lucene.net(4.8.0) 学习问题记录三: 索引的创建 IndexWriter 和索引速度的优化

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

  4. javascript瀑布流

    哇,瀑布流,是的,不错,不错,真的不错,很好玩的样子,于是自己想玩玩啊,来吧,就玩起. 循序渐进,我这里采用原生的js代码来书写.为了方便大家运行代码,我就全部样式和CSS都写在html里面了,当然还 ...

  5. fgets的用法

    fgets的用法:    char *fgets(char *s, int size, FILE *stream);       fgets()  reads  in  at most one les ...

  6. HTML知识点总结之ul,ol,li标签

    HTML列表分为有序列表,无序列表和描述列表.我们常用的是有序列表(ol)与无序列表(ul). 有序列表 <ol>标签就可以定义一个有序列表,之所以称其为有序列表,是因为可以使列表具有排序 ...

  7. [转载]mysql绑定参数bind_param原理以及防SQL注入

    假设我们的用户表中存在一行.用户名字段为username.值为aaa.密码字段为pwd.值为pwd.. 下面我们来模拟一个用户登录的过程.. <?php $username = "aa ...

  8. Django-常用模板标签及过滤器

    常用模板标签及过滤器 标签和过滤器完整介绍 https://docs.djangoproject.com/en/1.11/ref/templates/builtins/ 模板的组成 HTML代码+ 逻 ...

  9. 第一个 spring-boot 程序

    本例使用 maven 作为项目管理工具 新建 pom.xml 文件,添加 spring-boot-starter-web 依赖: <dependency> <groupId>o ...

  10. 【转】Memory gates checking failed because the free memory***解决办法

    Issue: Vault users cannot connect. VLOGS show the following error: Memory gates checking failed beca ...