<span style="color:#3333ff;background-color: rgb(255, 255, 255);">/* _______________________________________________________________________________________ author : Grant yuan time : 2014.7.21 algorithm : Binary Search explain : 如果i*m<=aa,则会有m个数满足结果,否则会有aa/i个数满足结果 ________________________________________________________________________________________ */ #include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<algorithm> #include<queue> #include<functional> #define INF 999999999 using namespace std; //long long a[100003][100003]; long long k; long long l,r,mid; long long n,m; long long M; inline bool can(long long aa) { long long sum=0; for(int i=1;i<=n;i++) { if(i*m<=aa) sum+=m; else sum+=aa/i; } if(sum>=k) return true; return false; } int main() { M=0; cin>>n>>m>>k; long long ans=1; l=1;r=n*m; while(l<=r){ mid=(long long)((l+r)*0.5); if(can(mid)) { ans=mid; r=mid-1; } else l=mid+1; } cout<<ans<<endl; } </span>
【组队赛三】—E Binary Search cf448D,布布扣,bubuko.com
原文地址:http://blog.csdn.net/yuanchang_best/article/details/38023447