mip001's Blog

Make Impossible Possible

A

选择 uA,vBu \in A, v\in B,使得 (x+u)×(y+v)(x + u)\times(y + v) 最大。

由于可以不选,可以把 00 加入到 AABB 中。

若固定 vv,则 f(u)=(x+u)(y+v)=(y+v)u+x(y+u)f(u) = (x + u)(y + v) = (y + v)u + x(y + u),是关于 uu 的一次函数,因此要取到极值,uu 一定在两个端点上。固定 uu 的情况同理。

因此全局最优解一定在这之中:

(x+minA)(y+minB),(x+minA)(y+maxB),(x+maxA)(y+minB),(x+maxA)(y+maxB).\begin{aligned} &(x+\min A)(y+\min B),\\ &(x+\min A)(y+\max B),\\ &(x+\max A)(y+\min B),\\ &(x+\max A)(y+\max B). \end{aligned}

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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
#define int long long
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const int maxn = 2e5 + 5;
int x, y, n, m;
void Solve() {
cin >> x >> y >> n >> m;
int maxx = 0, minx = 0;
int maxy = 0, miny = 0;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
maxx = max(maxx, a);
minx = min(minx, a);
}
for (int i = 1; i <= m; i++) {
int b;
cin >> b;
maxy = max(maxy, b);
miny = min(miny, b);
}
maxx += x, minx += x, maxy += y, miny += y;
cout << max(max(maxx * maxy, minx * miny), max(maxx * miny, minx * maxy)) << endl;

}
signed main() {
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--) {
Solve();
}
return 0;
}

F

把总期望拆成 每盏灯打开时的 连续段的期望个数 之和。

给每盏灯独立分配一个 [0,1][0,1] 上的均匀随机数 UiU_i,按 UiU_i 从小到大的顺序开灯。由于这些随机数几乎一定两两不同,它们的相对大小构成一个均匀随机排列,与原问题完全等价。

亮灯连续段的数量等于「既是亮着的,又是所在段的起点」的位置数。位置 jj 是起点,需要满足:

  • jj 盏灯亮着。
  • j=1j=1,或第 j1j-1 盏灯不亮。

设灯 ii 正在打开,Ui=xU_i=x

1. 端点 i=1i=1

11 盏灯一定是起点。位置 22 因为左边有灯 11 亮着,不可能是起点。

其余 n2n-2 个位置 j3j\ge3 成为起点的概率均为 x(1x)x(1-x)(自身亮且左边不亮)。

E[C1U1=x]=1+(n2)x(1x).\mathbb E[C_1\mid U_1=x]=1+(n-2)x(1-x).

积分得

E[C1]=1+n26=n+46.\mathbb E[C_1]=1+\frac{n-2}{6}=\frac{n+4}{6}.

2. 端点 i=ni=n

位置 11 成为起点的概率为 xx。位置 nn 成为起点的概率为 1x1-x(左边不亮)。

其余 n2n-2 个位置成为起点的概率为 x(1x)x(1-x)

E[CnUn=x]=x+(1x)+(n2)x(1x)=1+(n2)x(1x),\mathbb E[C_n\mid U_n=x]=x+(1-x)+(n-2)x(1-x)=1+(n-2)x(1-x),

同样得到

E[Cn]=n+46.\mathbb E[C_n]=\frac{n+4}{6}.

3. 内部点 2in12\le i\le n-1

  • 位置 11:概率 xx
  • 位置 ii:正在打开,它成为起点要求左边不亮,概率 1x1-x
  • 位置 i+1i+1:左边是 ii 已亮,不可能成为起点,概率 00
  • 其余 n3n-3 个位置:概率 x(1x)x(1-x)

E[CiUi=x]=x+(1x)+(n3)x(1x)=1+(n3)x(1x).\mathbb E[C_i\mid U_i=x]=x+(1-x)+(n-3)x(1-x)=1+(n-3)x(1-x).

积分得

E[Ci]=1+n36=n+36.\mathbb E[C_i]=1+\frac{n-3}{6}=\frac{n+3}{6}.

汇总

S=aiS=\sum a_i

E[总分]=n+36i=1nai+a16+an6=(n+3)S+a1+an6.\begin{aligned} \mathbb E[\text{总分}] &= \frac{n+3}{6}\sum_{i=1}^n a_i+\frac{a_1}{6}+\frac{a_n}{6}\\[4pt] &= \boxed{\frac{(n+3)S+a_1+a_n}{6}}. \end{aligned}

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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"
// #define int long long
const int mod = 998244353;
const int maxn = 2e5 + 5;
int qpow(int a, int n) {
int res = 1;
while (n) {
if (n & 1) res = 1ll * res * a % mod;
a = 1ll * a * a % mod;
n /= 2;
}
return res;
}
int n;
int a[maxn];
void Solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = 0;
if (n == 1) {
cout << a[1] << endl;
return;
}
ans = 1ll * (n + 4) * (a[1] + a[n]) % mod;
for (int i = 2; i < n; i++) {
ans = (ans + 1ll * (n + 3) * (a[i]) % mod) % mod;
}
cout << 1ll * ans * qpow(6, mod - 2) % mod << endl;
}
signed main() {
// freopen("1006.in", "r", stdin);
// freopen("1006.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T;
cin >> T;
while (T--) {
Solve();
}
return 0;
}

E

构造 S=a...ab...bS = a...ab...b,字符集设为 22

aa 的数量为 k1k_1bb 的数量为 k2k_2

aa 串对答案的贡献为 i=0k11i=k1(k11)2\sum^{k_1 - 1}_{i = 0}i = \frac{k_1(k_1 - 1)}{2},全 bb 串对答案的贡献为 k2k_2

所以只需要找到最大的 k1k_1,使得 k1(k11)2k\frac{k_1(k_1 - 1)}{2} \leq k,然后再填 kk1(k11)2k - \frac{k_1(k_1 - 1)}{2}bb 就行了。

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
#include <bits/stdc++.h>

using namespace std;
using i64 = long long;
#define int long long
#define endl "\n"

const int inf = 2e9;
const int maxn = 1e6 + 5;
int k;
void solve() {
cin >> k;
int n = 1;
while (n * (n + 1) / 2 <= k) ++n;
--n;
vector<char> ans;
for (int i = 1; i <= n + 1; i++) ans.push_back('a');
for (int i = 1; i <= k - n * (n + 1) / 2; i++) ans.push_back('b');
cout << ans.size() << " " << 2 << endl;
for (char x : ans) cout << x;
cout << endl;
}

signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
solve();
}
return 0;
}

这是一篇个人经验谈。

尽管到最后我的成绩仍然不算顶尖(sc 3k 名左右),但是考虑到我高三也在疯狂摆烂,整个高中实际有效学习文化课时长非常少,约 6 个月,高三实际复习时长约 3 个月。因此我的经验也许相当有参考性,不过否采用仍请读者自行衡量。

阅读全文 »

Gemini 老师手把手教你读后续写模板(雾

阅读全文 »

旅游第一,测试第二

阅读全文 »

高三退役骨灰选手的游(玩)记(录)之三。

阅读全文 »

周末一时兴起跟 xhr 和 khz 打了一场 Ucup,随便打打还打进了铜牌区,赢!

L. Recover Statistics

开始前没准备充分,比赛开始的时候 khz 都还没登上我们的账号,于是 xhr 被迫去给 khz 整账号,基本上前几分钟都只有我一个人在看题。我是正开的,凭心情一直浏览到了 G 题,感觉是个签到,就开始想 G。

等到 xhr 他们整好了账号,一看榜已经有人过 L 了,于是就愉快地决定开始跟榜,我们的策略是每道题都要有两个人一起做,所以我就放了 G,跟 xhr 一起看 L。khz 似乎在看 A。

L 很简单,按顺序输出 5050aa4545bb44cc11c+1c+1 即可。

阅读全文 »
0%