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 }