codeforces D. Multiplication Table

http://codeforces.com/contest/448/problem/D

题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数。

思路:1-n×m二分枚举,然后统计比小于等于x的数的个数与k相比较。

 1 #include <cstdio>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define maxn 1000100
 6 #define ll long long
 7 using namespace std;
 8 const int inf=1<<30;
 9 
10 ll n,m,k;
11 ll a[maxn];
12 ll dp[5001][5001];
13 
14 bool ok(ll x)
15 {
16     ll cnt=0;
17     for(int i=1; i<=n; i++)
18     {
19        cnt+=min(x/(ll)i,m);
20     }
21     if(cnt>=k) return true;
22     return false;
23 }
24 
25 int main()
26 {
27     cin>>n>>m>>k;
28     ll l=1,r=n*m;
29     ll ans;
30     while(l<=r)
31     {
32         ll mid=(l+r)>>1;
33         if(ok(mid))
34         {
35            ans=mid;
36            r=mid-1;
37         }
38         else l=mid+1;
39     }
40     cout<<ans<<endl;
41     return 0;
42 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/4335360.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值