題意:
給定數字 a、b,可以進行如下兩種操作:(1) a = ? a b ? a = \lfloor \frac{a}{b} \rfloor a=?ba??;(2) b = b + 1 b = b + 1 b=b+1,問最少進行多少次操作才能將 a 變為 0,有 t 組資料, 1 ≤ a , b ≤ 1 0 9 1 \le a,b \le 10^9 1≤a,b≤109, 1 ≤ t ≤ 100 1\le t \le 100 1≤t≤100,
思路:
- 假定進行 x 次 1 操作,y 次 2 操作,一定是先把 2 操作進行完了之后才進行 1 操作,
- 考慮最差的情況,a = 1 0 9 10^9 109, b = 2,這種情況下需要 30 次 1 操作可以把 a 變為 0,也就是說,無論 a、b 的值是什么( b ≠ 1 b ≠ 1 b?=1),最多只需要 30 次 1 操作就可以把 a 變為 0,因此,我們可以列舉進行 0 ~ 30 次的 2 操作,對應的算出 1 操作 的次數,通過這樣的列舉,就可以找到最小的總的操作次數,
AC Codes:
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <deque>
#include <list>
#include <iomanip>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <assert.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(k); 輸出k位精度
//cout << setw(k); 設定k位寬度
const int N = 2e5 + 6, M = 1e9 + 7, INF = 0x3f3f3f3f;
int main() {
//freopen("/Users/xumingfei/Desktop/ACM/test.txt", "r", stdin);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int t;
cin >> t;
while (t--) {
int a, b;
cin >> a >> b;
int ans = 2e9;
for (int i = 0; i <= 30; i++) {
if (b + i == 1) continue;
int x = a, now = 0;
while (x > 0) {
now++;
x /= b + i;
}
ans = min(ans, now + i);
}
cout << ans << '\n';
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/260086.html
標籤:其他
下一篇:linux下Appium+Python移動應用自動化測驗實戰---4.Android Emulator Headless
