2025 暑期集训A班 模拟赛#3
Chthohepta · · 个人记录
A. 禁止翻倍(double)
题意
给定
思路
将
可以 dp。设
- 当
i 为偶数时,dp_{i, 1} = \min(dp_{\frac{i}{2}, 0}, dp_{\frac{i}{2}, 1}) + cnt_i, dp_{i, 0} = dp_{\frac{i}{2}, 1}
当
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e5 + 2, M = 1e6 + 1;
int n, a[N];
int cnt[M];
ll ans = 0;
int dp[M][2];
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("double.in", "r", stdin);
freopen("double.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; i ++){
cin >> a[i];
cnt[a[i]] ++;
}
for(int i = 1; i < M; i ++){
if(i % 2 == 1){
dp[i][1] = cnt[i];
dp[i][0] = 0;
}
else{
dp[i][1] = min(dp[i >> 1][0], dp[i >> 1][1]) + cnt[i];
dp[i][0] = dp[i >> 1][1];
}
if((i << 1) >= M){
ans += min(dp[i][0], dp[i][1]);
}
}
cout << ans;
return 0;
}
/***
5
1 2 4 3 6
***/
B. 飞石水上漂(rubble)
题意
飞石大师朝着水面掷出一块飞石。每当飞石在飞行
- 石头没能弹起,沉入水中。
- 石头从水面弹起,飞行
\lfloor \frac{x}{2} \rfloor 米后再次击中水面;
飞石大师希望掷出一块总共飞行了恰好
它可以任意控制掷出时的飞行距离,也可以控制每一次击中水面时是弹起还是下沉。请判断,为了达成这一目标,飞石掷出时的飞行距离至少需要是多少?
思路
枚举弹起的次数,对于每一种次数,掷出的距离增大,飞行距离增大,所以可以二分。
对于枚举的所有次数,当距离刚好等于
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e7 + 1;
int T;
ll d;
ll l, r, mid, p;
ll ans;
ll len(ll s, ll cnt){
ll sum = 0;
while(cnt --){
sum += s;
s >>= 1;
}
return sum;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("rubble.in", "r", stdin);
freopen("rubble.out", "w", stdout);
cin >> T;
while(T --){
cin >> d;
ans = 1e18;
for(int i = 60; i >= 1; i --){
l = 1, r = 1e18, p = 0;
while(l <= r){
mid = (l + r) >> 1;
if(len(mid, i) <= d){
p = mid;
l = mid + 1;
}
else{
r = mid - 1;
}
}
if(len(p, i) == d){
ans = p;
break;
}
}
cout << ans << '\n';
}
return 0;
}
/***
3
10
5
1123581321345589
***/
D. 010子串(olo)
题意
我们规定字符串
请统计所有包含
思路
因为分割方案中分割数最小,所以分割的相邻字串的内容不能相等。
设
不满足用总数减去满足。
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 1e6 + 2, mod = 1e9 + 7;
int T, n, m, a, b;
ll jc[N];
ll sum, sum2;
ll L, R;
ll po(ll a, ll b){
ll ans = 1;
while(b){
if(b & 1){
ans = (ans * a) % mod;
}
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
ll c(ll n, ll m) {
if(n < m){
return 0;
}
if(m <= 0){
return 0;
}
return jc[n - 1] * po(jc[m - 1], mod - 2) % mod * po(jc[n - m], mod - 2) % mod;
}
int main(){
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
freopen("olo.in", "r", stdin);
freopen("olo.out", "w", stdout);
jc[0] = 1;
for(int i = 1; i < N; i ++){
jc[i] = (jc[i - 1] * i) % mod;
}
cin >> T;
while(T --){
cin >> n >> m >> a >> b;
sum = jc[n] * po(jc[n - a], mod - 2) % mod * po(jc[a], mod - 2) % mod;
L = m >> 1;
R = m - L;
sum2 = (c(a, L) * c(b, R) % mod + c(b, L) * c(a, R) % mod) % mod;
cout << sum2 << ' ' << (sum - sum2 + mod) % mod << '\n';
}
return 0;
}
/***
1
4 2 2 2
***/