codeforces448D Multiplication Table(二分答案)
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·105; 1 ≤ k ≤ n·m).
Print the k-th largest number in a n × m multiplication table.
2 2 2
2
2 3 4
3
1 10 5
5
A 2 × 3 multiplication table looks like this:
1 2 3 2 4 6
我們要知道一個規律 :在乘法表中第i行小於x的數有x/i個
因此在[1,m*n]內二分答案 即可
程式碼如下:
#include <iostream>
using namespace std;
typedef long long LL;
LL n,m,k;
bool judge(LL x)
{
LL res=0;
for(int i=1;i<=n;i++){
LL tmp=min(i*m,x);
res+=tmp/i;//第i行小於x數的個數為x/i;
}
return res<k;
}
LL binary_search(LL l,LL r)
{
LL mid;
while(l<r){
mid=(l+r)>>1;
if(judge(mid))
l=mid+1;
else
r=mid;
}
return r;
}
int main()
{
while(cin>>n>>m>>k){
LL l=1,r=n*m;
LL ans=binary_search(l,r);
cout<<ans<<endl;
}
return 0;
}
相關文章
- [6 kyu] Multiplication table
- HDU 4951 Multiplication table(找規律)
- Codeforces 448D Multiplication Table
- 二分答案法
- UVALive 7511 Multiplication Table (數學模擬題)
- c++ 二分答案C++
- 二分答案解題技巧
- 「暑期訓練」「Brute Force」 Multiplication Table (CFR256D2D)
- 【二分答案】P2390 地標訪問
- A Multiplication Game (博弈,規律)GAM
- LeetCode-Sparse Matrix MultiplicationLeetCode
- POJ 2773 Happy 2006 (二分答案+容斥)APP
- 【題解】AGC007E | 二分答案 複雜度分析GC複雜度
- C240817C. 團隊協作:二分答案+貪心
- HDU 4920 Matrix multiplication(矩陣相乘)矩陣
- 7月18日刷題記錄 二分答案跳石頭遊戲Getting遊戲
- Gym 101962I Colonial Mansions(二分答案 + 資料結構)資料結構
- ZOJ Problem Set - 1094 Matrix Chain MultiplicationAI
- (DP) CF1861D Sorting By Multiplication
- 資訊學奧賽初賽天天練-81-NOIP2015普及組-完善程式-二分答案、二分查詢、中位數、二分邊界、二分時間複雜度時間複雜度
- 例題6-3 Matrix Chain Multiplication ,Uva 442AI
- NOIP2012借教室[線段樹|離線 差分 二分答案]
- 【TJOI2016】【bzoj4552】排序(二分答案+線段樹01排序)排序
- BZOJ 1044: [HAOI2008]木棍分割 DP,字首和優化,二分答案優化
- POJ 3318 Matrix Multiplication(隨機化演算法)隨機演算法
- HDU4920 Matrix multiplication (CPU cache對程式的影響)
- 二分
- 拆分Table 為Partition Table
- 資訊學奧賽初賽天天練-93-CSP-S2023閱讀程式3-sort排序、同底對數求和、二分查詢、二分答案排序
- 二分插入與二分查詢
- [Oracle] Partition table exchange Heap tableOracle
- html~table、table cell的使用HTML
- 如何修改table及partitions Table
- table
- 二分板子
- User defined table type and table valued parameters
- 二分查詢基礎專題——二分模板
- 二分查詢(一)——純粹的二分查詢