CF1898B Milena and Admirer
题意
给你一个数组
思路
首先我们要明确:把一个数
这是一道贪心题。我们倒着遍历这个数组,如果当前遍历到的数
下面来解释一下,比如数组
代码
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <algorithm>
using namespace std;
const int N = 2e5 + 10;
int a[N];
void solve() {
int n;
cin >> n;
long long ans = 0;
for (int i = 1; i <= n; i ++)
cin >> a[i];
int b = a[n];
for (int i = n - 1; i; i --)
if (a[i] > b)
{
int k = (a[i] - 1) / b;
ans += k;
b = a[i] / (k + 1);
}
else
b = a[i];
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
int t;
cin >> t;
while (t --)
solve();
return 0;
}