惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
Help Net Security
Help Net Security
Y
Y Combinator Blog
WordPress大学
WordPress大学
D
DataBreaches.Net
N
Netflix TechBlog - Medium
U
Unit 42
爱范儿
爱范儿
MyScale Blog
MyScale Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园 - 司徒正美
Google DeepMind News
Google DeepMind News
D
Docker
H
Help Net Security
Stack Overflow Blog
Stack Overflow Blog
宝玉的分享
宝玉的分享
博客园_首页
Microsoft Security Blog
Microsoft Security Blog
Engineering at Meta
Engineering at Meta
Know Your Adversary
Know Your Adversary
P
Privacy & Cybersecurity Law Blog
P
Proofpoint News Feed
T
Tenable Blog
S
Schneier on Security
V
Vulnerabilities – Threatpost
V
V2EX
T
Tor Project blog
Security Latest
Security Latest
S
Securelist
G
Google Developers Blog
NISL@THU
NISL@THU
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
小众软件
小众软件
Google Online Security Blog
Google Online Security Blog
阮一峰的网络日志
阮一峰的网络日志
W
WeLiveSecurity
IT之家
IT之家
I
InfoQ
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
月光博客
月光博客
I
Intezer
T
The Blog of Author Tim Ferriss
C
Cisco Blogs
博客园 - 【当耐特】
The GitHub Blog
The GitHub Blog
Cloudbric
Cloudbric
Scott Helme
Scott Helme
The Cloudflare Blog
L
LINUX DO - 热门话题

Shiroha白羽的博客

Golang 踩坑 —— interface 为参数的时候传 nil 指针 Codeforces Round 925 (Div. 3) Codeforces Round 924 (Div. 2) Codeforces Round 923 (Div. 3) Codeforces Round 922 (Div. 2) Codeforces Round 921 (Div. 2) Educational Codeforces Round 161 (Rated for Div. 2) Codeforces Round 920 (Div. 3) Codeforces Round 919 (Div. 2) Hello 2024 Good Bye 2023 Codeforces Round 918 (Div. 4) 个人备份的常用 macOS 清理命令 Codeforces Round 917 (Div. 2) Pinely Round 3 (Div. 1 + Div. 2) Educational Codeforces Round 160 (Rated for Div. 2) Codeforces Round 915 (Div. 2) Codeforces Round 914 (Div. 2) Codeforces Round 913 (Div. 3) Educational Codeforces Round 159 (Rated for Div. 2) Codeforces Round 912 (Div. 2) Codeforces Round 911 (Div. 2) CodeTON Round 7 (Div. 1 + Div. 2, Rated, Prizes!) Educational Codeforces Round 158 (Rated for Div. 2) Codeforces Round 910 (Div. 2) Codeforces Round 909 (Div. 3) Codeforces Round 908 (Div. 2) Educational Codeforces Round 157 (Rated for Div. 2) C++自定义的字面量 Codeforces Round 907 (Div. 2) Codeforces Round 916 (Div. 3) 关于 LRU map 的一些灵感 2023 杭州站 ICPC 现场赛 反复横跳的 Clang-Tidy(cert-dcl21-cpp) Codeforces Round 906 (Div. 2) 一段奇怪的 CPP 代码 Codeforces Round 905 (Div. 3) Codeforces Round 904 (Div. 2) Codeforces Round 903 (Div. 3) Educational Codeforces Round 156 (Rated for Div. 2) Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round) Codeforces Round 901 (Div. 2) Codeforces Round 900 (Div. 3) Codeforces Round 899 (Div. 2) Educational Codeforces Round#155 (Div. 2) Codeforces Round 898 (Div. 4) CodeTON Round 6 (Div. 2) Codeforces Round 897 (Div. 2) Codeforces Round 896 (Div. 2) Codeforces Round 887 (Div. 2) Codeforces Round 895 (Div. 3) 左值-右值-将亡值 blog.mauve.icu Pinely Round 2 (Div. 1 + Div. 2) Harbour.Space Scholarship Contest 2023-2024 (Div. 1 + Div. 2) Codeforces Round 894 (Div. 3) Codeforces Round 888 (Div. 3) Educational Codeforces Round#153 (Div. 2) Codeforces Round 893 (Div. 2) OTPAUTH,两步验证中的通用协议 Codeforces Round 892 (Div. 2) Codeforces Round 891 (Div. 3) Codeforces Round 890 (Div. 2) Educational Codeforces Round#152 (Div. 2) blog.mauve.icu Java Script 的 null 和 undefined 随想 记一次 SQL LEFT JOIN 没有得到预期结果的错误 Codeforces Round#789(Div. 2) GCC/G++ 预编译头性能优化 使用 Junit5 和 Mockito 实现 SpringBoot 的单元测试最优美的解决方案 centOS 防火墙 docker-compse 的问题 C++ 语言实现动态变化的线程池 Codeforces Round#744 (Div. 3) 计算机图形学 Windows 通过网络访问 WSL2 原生 JavaScript 实现图片裁剪 面试复习(计算机图形学) 面试复习(算法) Codeforces Round#706(Div. 2)-Let's Go Hiking 面试复习(Java) 面试复习(Git) 面试复习(Linux) 面试复习(数据库) 面试复习(计算机网络) 面试复习(操作系统) 面试复习(C++) Codeforces Round#699 (Div. 2) 清理 WSL2 的磁盘占用 Codeforces Round#697 (Div. 3) Windows 下的 NTFS 驱动器索引 BUG 计算机网络复习 记一次 Navicat 连接 MySQL 一直报认证错误(Access denied) 计算机网络实验复习 WSL1 使用 Docker 一直无法启动 2020牛客暑期多校训练营(第三场)D-Points Construction Problem——构造 2020牛客暑期多校训练营(第三场)E-Two Matchings——复杂思维与简单dp 2020牛客暑期多校训练营(第二场)I-Interval——最大流转对偶图求最短路 Educational Codeforces Round 80 D. Minimax Problem——二分+二进制处理 Codeforces Round 606 E. Two Fairs——图论 Codeforces Round 612 (Div. 2) C. Garland——DP
Codeforces Round 939 (Div. 2)
Shiroha · 2024-04-21 · via Shiroha白羽的博客

A. Nene’s Game

大致题意

有一排士兵,按照 $1,2,3,4 \dots n$ 的顺序喊,每次喊道 $a_i$ 的位置就踢出队伍,问最后剩下几个人

思路

只需要关注第一个被踢出去的人就行了

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int k, q, s;
cin >> k >> q;
cin >> s;
for (int i = 1; i < k; ++i) {
int tmp;
cin >> tmp;
}
for (int i = 0; i < q; ++i) {
int n;
cin >> n;
cout << min(n, s - 1) << " \n"[i == q - 1];
}
}
}

B. Nene and the Card Game

大致题意

有一组牌,每种数字只出现在两张牌上

现在将这组牌打散后分给两个人,并进行游戏。游戏的每一轮,当前的出牌手需要出一张牌,如果这张牌上的数值的另外一张已经在场上了,那么就会获得 1 份

现在给你其中一个人的手牌,问最多可以得到多少分

思路

两边的牌是映射的,所以先手出一张,后手跟一张,这样是刚刚好的,所以先手只能赚到那些两张牌都在自己手里的分数

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int n;
cin >> n;
set<int> st;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
st.insert(tmp);
}
cout << n - st.size() << endl;
}
}

C. Nene’s Magical Matrix

大致题意

有一个矩阵,现在允许每次往一行或者一列上覆盖写 $1, 2, 3 \dots n$ 的某一个排列,问最终的整个矩阵的求和是多少

思路

每个位置都能变成它的横坐标和纵坐标里的较大者,简单模拟即可

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void solve() {
int _;
cin >> _;
for (int tc = 0; tc < _; ++tc) {
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) ans += max(i, j) + 1;
cout << ans << ' ' << 2 * n << endl;
for (int i = n - 1; i >= 0; --i) {
cout << 1 << ' ' << i + 1;
for (int j = 0; j < n; ++j) cout << ' ' << j + 1;
cout << endl;
cout << 2 << ' ' << i + 1;
for (int j = 0; j < n; ++j) cout << ' ' << j + 1;
cout << endl;
}
}
}

D. Nene and the Mex Operator

大致题意

有一个初始数组,允许你每次选择一个子串,将其的每一个值变成这个子串的 $MEX$,问可以让整个数组的所有位置之和最大是多少

思路

注意这个数组最大只能是 18 个数值,所以可以随意暴力

容易得到,最终一定可以把选择的区间都变成和当前区间长度相同的那个值,比如区间长度为 $3$,那么最终这个区间可以变成三个 $3$

首先通过 dp 计算出哪些区间要进行上面的操作,然后再递归构建即可

比如我通过一定手段能够构建 $0, 1, 2, 3, 4, x$,就能通过一次 $MEX$ 得到 $5, 5, 5, 5, 5, 5$,
这个时候如果我再去尝试构建 $0, 1, 2, 3, 4$ 就可以重复之前的构建过程了,重复构建前五个值,相当于递归两次即可

AC code

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
void solve() {
int n;
cin >> n;
vector<int> data(n), dp(n), dr(n);
for (auto &i: data) cin >> i;
dp[0] = data[0] >= 1 ? data[0] : 1;
dr[0] = data[0] >= 1 ? -1 : 0;
for (int i = 1; i < n; ++i) {
dp[i] = dp[i - 1] + data[i];
dr[i] = -1;
for (int j = i; j >= 1; --j)
if (dp[j - 1] + (i - j + 1) * (i - j + 1) > dp[i]) {
dp[i] = dp[j - 1] + (i - j + 1) * (i - j + 1);
dr[i] = j;
}
if ((i + 1) * (i + 1) > dp[i]) {
dr[i] = 0;
dp[i] = (i + 1) * (i + 1);
}
}
vector<pair<int, int>> ans;
ans.reserve(2e5);

auto zero = [&](int l, int r) {
bool flag = true;
for (int i = l; i <= r; ++i) if (data[i] == 0) flag = false;
if (flag) ans.emplace_back(l, r);
else {
ans.emplace_back(l, r);
ans.emplace_back(l, r);
}
for (int i = l; i <= r; ++i) data[i] = 0;
};
function<void(int, int)> dfs = [&](int l, int r) {
if (l == r) {
if (data[l] == 0) return;
ans.emplace_back(l, l);
return;
}
dfs(l, r - 1);
ans.emplace_back(l, r);
ans.emplace_back(l, r - 1);
data[r] = r - l;
dfs(l, r - 1);
};

auto f = [&](int l, int r) {
zero(l, r);
dfs(l, r);
ans.emplace_back(l, r);
};
vector<pair<int, int>> lr;
for (int i = n - 1; i >= 0; --i) {
if (dr[i] == -1) continue;
f(dr[i], i);
i = dr[i];
}

cout << dp[n - 1] << ' ' << ans.size() << endl;
for (auto &[a, b]: ans) cout << a + 1 << ' ' << b + 1 << endl;
}