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

推荐订阅源

Latest news
Latest news
Schneier on Security
Schneier on Security
Cyberwarzone
Cyberwarzone
L
LINUX DO - 热门话题
P
Privacy International News Feed
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
Scott Helme
Scott Helme
V
Vulnerabilities – Threatpost
I
Intezer
aimingoo的专栏
aimingoo的专栏
月光博客
月光博客
Simon Willison's Weblog
Simon Willison's Weblog
GbyAI
GbyAI
Google DeepMind News
Google DeepMind News
小众软件
小众软件
博客园 - 三生石上(FineUI控件)
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
S
Secure Thoughts
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
www.infosecurity-magazine.com
www.infosecurity-magazine.com
爱范儿
爱范儿
L
Lohrmann on Cybersecurity
M
MIT News - Artificial intelligence
H
Hacker News: Front Page
Last Week in AI
Last Week in AI
L
LINUX DO - 最新话题
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
Project Zero
Project Zero
A
About on SuperTechFans
Know Your Adversary
Know Your Adversary
Security Latest
Security Latest
有赞技术团队
有赞技术团队
Y
Y Combinator Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Microsoft Security Blog
Microsoft Security Blog
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
H
Heimdal Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG

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) 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 一直无法启动 我的ACM脚印 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 898 (Div. 4)
Shiroha · 2023-09-24 · via Shiroha白羽的博客

A. Short Sort

大致题意

有三张卡片,分别为 $a, b, c$,已经在桌面上乱序排好,最多交换两张卡片的位置,问是否能够变成有序的 $a, b, c$

思路

简单题,判断一下是不是至少有一位是保持 $a, b, c$ 的顺序即可

AC code

1
2
3
4
5
6
7
8
9
10
11
12
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
string str;
str.reserve(3);
cin >> str;
int cnt = 0;
for (int i = 0; i < 3; ++i) cnt += str[i] == i + 'a';
cout << (cnt == 1 || cnt == 3 ? "YES" : "NO") << endl;
}
}

B. Good Kid

大致题意

有一个数组,允许你给其中一个值加一,问最终所有值的乘积最大是多少

思路

简单题,如果有两个及以上的 $0$,那么最终结果一定还是 $0$。如果只有一个 $0$,那就等于忽略这个 $0$ 即可,剩下的情况,因为加了之后的效果是 $\frac{x+1}{x}$,所以 $x$ 越小越好,那么让最小的值 $+1$ 即可

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n;
cin >> n;
int p = 1, zero = 0, mi = INT_MAX;
for (int i = 0; i < n; ++i) {
int tmp;
cin >> tmp;
p *= (tmp == 0 ? 1 : tmp);
zero += tmp == 0;
mi = min(mi, tmp);
}

if (zero >= 2) cout << 0 << endl;
else if (zero == 1) cout << p << endl;
else cout << (p / mi * (mi + 1)) << endl;
}
}

C. Target Practice

大致题意

有一个飞镖靶,根据结果计算总分

思路

简单题,根据当前的下标距离四个边最小值是多少即可

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 ts = 0; ts < _; ++ts) {
string str;
str.reserve(10);
int ans = 0;
for (int i = 0; i < 10; ++i) {
cin >> str;
for (int j = 0; j < 10; ++j) {
if (str[j] == '.') continue;
int code = min(min(i + 1, 10 - i), min(j + 1, 10 - j));
ans += code;
}
}
cout << ans << endl;
}
}

D. 1D Eraser

大致题意

有一个串,其中有白色和黑色方块,每次可以选择连续 $k$ 个块让其变成白色,问最少几步可以全部变成白色

思路

简单题,从左往右考虑即可,毕竟最左边遇到的第一个黑色方块肯定需要消耗一次操作,为了最大化使用必定会让 $k$ 个的左边界是当前的黑色方块

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 ts = 0; ts < _; ++ts) {
int n, k;
cin >> n >> k;
string str;
str.reserve(n);
cin >> str;
int last = -k - 1, ans = 0;
for (int i = 0; i < n; ++i) {
if (str[i] == 'W') continue;
if (i - last + 1 <= k) continue;
last = i;
ans++;
}
cout << ans << endl;
}
}

E. Building an Aquarium

大致题意

有一个线性水池,水池底部形状已知,最多可以使用 $x$ 个单位的水,问水池两边应该造多高才能尽可能容纳更多的水的同时,在水池满的时候不会使用超过给出的水

思路

简单题,二分答案即可

AC code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define int long long

void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n, x;
cin >> n >> x;
vector<int> data(n);
for (auto &item: data) cin >> item;
int l = 0, r = 2e9 + 10LL;
while (l + 1 < r) {
int mid = (l + r) >> 1;
int sum = 0;
for (auto &item: data) sum += item >= mid ? 0 : mid - item;
if (sum > x) r = mid;
else l = mid;
}
cout << l << endl;
}
}

F. Money Trees

大致题意

给出一个数组,其每个值都有两个属性:$a, h$,需要找到一个连续的子数组,使得这个连续的子数组 $[l, r]$的 $h$ 值满足 $\forall i \in [l, r], h_{i-1} \space mod \space h_i = 0$,同时 $\sum_{i=l}^{r} a_i \leq x$

问最长的子数组的长度

思路

也是二分答案即可,毕竟在确定要找的最终串的长度的情况下,只需要 $O(n)$ 即可求出是否符合预期,注意平移区间的时候状态的转化

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
62
63
64
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n, k, ans = 0;
cin >> n >> k;
vector<int> a(n), h(n);
for (auto &item: a) cin >> item;
for (auto &item: h) cin >> item;
for (auto &item: a) if (item <= k) ans = 1;
int l = 0, r = n + 1;
while (l + 1 < r) {
int mid = (l + r) >> 1;
if (mid == 1) {
if (ans >= 1) l = mid;
else r = mid;
continue;
}
int x = 0, y = 0, sum = 0;
bool flag = false;

auto findNext = [&]() {
x = y;
y += 1;
sum = a[x];
while (y - x != mid && x < n && y < n) {
if (h[y - 1] % h[y] != 0) {
x = y;
y += 1;
sum = a[x];
} else {
sum += a[y];
y++;
}
}

if (y - x == mid && sum <= k) {
ans = max(ans, mid);
flag = true;
}
return y - x == mid;
};
auto move = [&]() {
if (y == n) return false;
if (h[y - 1] % h[y] != 0) return false;
sum -= a[x];
sum += a[y];
y++;
x++;
if (sum <= k) {
ans = max(ans, mid);
flag = true;
}
return true;
};

while (findNext()) while (move());
if (flag) l = mid;
else r = mid;
}

cout << ans << endl;
}
}

G. ABBC or BACB

大致题意

有一个字符串,由 $A, B$ 两个字母组成,每次可以将 $AB$ 转为 $BC$,或者将 $BA$ 转为 $CB$,问最多可以操作几次

思路

很显然,如果是一串联系的 $A$,然后其中一侧有一个 $B$,那么这种情况下的答案就是 $A$ 的数量

那么将整个数组拆成所有连续的 $A$ 段,然后为每个 $A$ 段找合理的 $B$ 即可。比如如果整个字符串开头或者结尾是 $B$,那么必然可以为每个 $A$ 段找到一个 $B$。除开上面的情况,只需要看看 $B 的数量是否大于等于 $A$ 段的数量即可,因为如果等于或者超过也必然可以分割。如果还不行,那么只能舍弃价值最低的 $A$ 串了

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
void solve() {
int _;
cin >> _;
string str;
str.reserve(2e5 + 10);
for (int ts = 0; ts < _; ++ts) {
cin >> str;
if (str.front() == 'B' || str.back() == 'B') {
int cnt = 0;
for (auto &item: str) cnt += item == 'A';
cout << cnt << endl;
continue;
}

vector<int> part(1, 0);
int cntB = 0;
for (char &i: str) {
cntB += i == 'B';
if (i == 'B') {
if (part.back() != 0) part.push_back(0);
} else part.back()++;
}

int tot = 0, mi = INT_MAX;
for (auto &item: part) {
tot += item;
mi = min(mi, item);
}
if (cntB < part.size()) tot -= mi;
cout << tot << endl;
}
}

H. Mad City

大致题意

有一个图,$n$ 个点,$n$ 条边,有两个人分别从 $a, b$ 出发,其中前者希望追赶后者,而后者希望摆脱前者的追捕,问能否追上

思路

首先,$n$ 个点和 $n$ 条边,那就意味着必然图中必然存在环。而两人速度相同,如果同时都在环上,那肯定追不到。所以必须要在后者进入环之前抓到,也就是提前或者刚好到达环上的某一个点。所以只需要找出后者刚进入环的时间点和位置,看看前者能否在指定时间内达到即可

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
void solve() {
int _;
cin >> _;
for (int ts = 0; ts < _; ++ts) {
int n, a, b;
cin >> n >> a >> b;
vector<int> deg(n + 1, 0);
vector<bool> vis(n + 1, false);
struct node {
int v, n;
};
vector<node> edge(n * 2);
vector<int> head(n + 1, -1);
for (int i = 0; i < n; ++i) {
int u, v;
cin >> u >> v;
edge[i << 1] = {v, head[u]};
edge[(i << 1) | 1] = {u, head[v]};
head[u] = i << 1;
head[v] = (i << 1) | 1;
deg[u]++;
deg[v]++;
}

// find circle
queue<int> q;
for (int i = 1; i <= n; ++i) if (deg[i] == 1) q.push(i);
while (!q.empty()) {
int cur = q.front();
q.pop();
vis[cur] = true;
for (int i = head[cur]; i != -1; i = edge[i].n)
if ((--deg[edge[i].v]) == 1 && !vis[edge[i].v]) q.push(edge[i].v);
}

// begin for b run away
int cost1, cost2 = INT_MAX, target;
queue<pair<int, int>> qs;
vector<bool> flag(n + 1, false);
qs.emplace(b, 0);
flag[b] = true;
while (!qs.empty()) {
auto cur = qs.front();
qs.pop();
if (!vis[cur.first]) {
cost1 = cur.second;
target = cur.first;
break;
}
for (int i = head[cur.first]; i != -1; i = edge[i].n)
if (!flag[edge[i].v]) {
qs.emplace(edge[i].v, cur.second + 1);
flag[edge[i].v] = true;
}
}

while (!qs.empty()) qs.pop();
for (int i = 0; i <= n; ++i) flag[i] = false;

qs.emplace(a, 0);
flag[a] = true;
while (!qs.empty()) {
auto cur = qs.front();
qs.pop();
if (cur.first == target) {
cost2 = cur.second;
break;
}
for (int i = head[cur.first]; i != -1; i = edge[i].n)
if (!flag[edge[i].v]) {
qs.emplace(edge[i].v, cur.second + 1);
flag[edge[i].v] = true;
}
}

cout << (cost1 < cost2 ? "YES" : "NO") << endl;
}
}