把ABC当成休闲,取代了打球
A题B题SB题就不写了
C
排序枚举长为k的区间左端点就行了
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;template<typename T> inline void CheckMax(T &A, T B) {A < B ? A = B : A;
}template<typename T> inline void CheckMin(T &A, T B) {A > B ? A = B : A;
}template <typename T> inline void read(T &x) {int c = getchar();bool f = false;for (x = 0; !isdigit(c); c = getchar()) {if (c == '-') {f = true;}}for (; isdigit(c); c = getchar()) {x = x * 10 + c - '0';}if (f) {x = -x;}
}int n, k;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y secondint a[MAXN];signed main() {read(n), read(k);for(int i = 1; i <= n; i++) read(a[i]);sort(a + 1, a + n + 1);int ans = 0x7FFFFFFF;for(int i = 1; i <= n - k + 1; i++) {ans = min(ans, a[i + k - 1] - a[i]);}cout << ans << endl;return 0;
}
D
考虑将x分成一些整的区间和单独的一个B或P
将区间从大到小枚举,每个区间最多出现2次
同时注意出去多余的B并加上中间的P
#include <bits/stdc++.h>
#define LL long long
#define db double
using namespace std;const int MAXN = 200200;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;template<typename T> inline void CheckMax(T &A, T B) {A < B ? A = B : A;
}template<typename T> inline void CheckMin(T &A, T B) {A > B ? A = B : A;
}template <typename T> inline void read(T &x) {int c = getchar();bool f = false;for (x = 0; !isdigit(c); c = getchar()) {if (c == '-') {f = true;}}for (; isdigit(c); c = getchar()) {x = x * 10 + c - '0';}if (f) {x = -x;}
}LL n;
long long k;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
#define X first
#define Y secondLL num[100], len[100], add[100], ans;int Find(LL x) {for(int i = 50; i >= 0; i--) {if(x >= len[i]) return i;}return -1;
}signed main() {read(n), read(k);num[0] = len[0] = 1;for(int i = 1; i <= 50; i++) num[i] = num[i - 1] * 2 + 1;for(int i = 1; i <= 50; i++) len[i] = len[i - 1] * 2 + 3;if(k == len[n]) {cout << num[n] << endl;return 0;}long long l = 1, m = n - 1;while(l < k) {if(l == k) break;for(LL i = m; i >= 0; i--) {if(k >= len[i] + l) {ans += num[i];l += len[i];m = i;break;}l++;if(l == k) break;}if(l == k) break;ans++, l++;if(l == k) break;}cout << ans << endl;return 0;
}