A - Another String Minimization 问题
水
B - Making Towers
很显然两个间隔为偶数的相同数字可以连在一起
C - Qpwoeirut And The City
奇数显然。偶数可以认为是选择一个偶数前缀和奇数后缀,结束了。
D - Chopping Carrots
不难想到枚举最小值然后二分 check,然后优化就是把最小值整除分块。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include<bits/stdc++.h> using namespace std;
typedef long long ll; typedef pair<int , int > pii; typedef unsigned long long ull;
namespace FastIO { template<typename T> inline T read(T& x) { x = 0; int f = 1; char ch; while (!isdigit(ch = getchar())) if (ch == '-') f = -1; while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x *= f; return x; } template<typename T, typename... Args> inline void read(T& x, Args &...x_) { read(x); read(x_...); return; } inline ll read() { ll x; read(x); return x; } }; using namespace FastIO;
const int N = 1e5+10;
int a[N], te[N], mxn[N]; int n, k;
inline int get(int l, int n) { return n / (n / l); }
inline void Input() { read(n, k); for(int i = 1; i <= n; i++) { read(a[i]); } }
inline void Work() { for(int i = 1; i <= n; i++) mxn[i] = 0; int mx = 0; for(int i = 1; i <= n; i++) { int tot = 0; for(int l = 1, r = 0; l <= min(k, a[i]); l = r + 1) { r = get(l, a[i]); te[++tot] = a[i] / l; } if(k > a[i]) te[++tot] = 0; reverse(te + 1, te + 1 + tot); mx = max(mx, te[1]); te[tot + 1] = 1e9; for(int j = 1; j <= tot; j++) { mxn[te[j]] = max(mxn[te[j]], te[j+1]); } } int ans = 1e9; for(int i = 0; i <= 100000; i++) { ans = min(ans, mx - i); mx = max(mx, mxn[i]); } printf("%d\n", ans); }
int main() { int T = read(); while(T--) { Input(); Work(); } return 0; }
|
E - Qpwoeirut and Vertices
这个是 Kruskal 重构树的模板题,我会单独写一篇来讲 Kruskal 重构树的。