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

推荐订阅源

B
Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
B
Blog RSS Feed
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
Recent Announcements
Recent Announcements
A
About on SuperTechFans
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google Online Security Blog
Google Online Security Blog
Google DeepMind News
Google DeepMind News
S
Schneier on Security
S
Secure Thoughts
T
The Exploit Database - CXSecurity.com
Martin Fowler
Martin Fowler
P
Proofpoint News Feed
Security Latest
Security Latest
Jina AI
Jina AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Recorded Future
Recorded Future
T
Tor Project blog
有赞技术团队
有赞技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
News | PayPal Newsroom
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
Forbes - Security
Forbes - Security
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
NISL@THU
NISL@THU
C
Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Google DeepMind News
Google DeepMind News
Project Zero
Project Zero
IT之家
IT之家
T
Threatpost
Cyberwarzone
Cyberwarzone
O
OpenAI News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
J
Java Code Geeks
P
Proofpoint News Feed
The Last Watchdog
The Last Watchdog
月光博客
月光博客
Latest news
Latest news
MongoDB | Blog
MongoDB | Blog
Apple Machine Learning Research
Apple Machine Learning Research

Louis C Deng's Blog

CS231n Lecture Note: Generative Models CS231n Lecture Note: Self-Supervised Learning CS231n Lecture Note: Large Scale Distributed Training 自動微分 | DIY 實現自己的 PyTorch From RNNs to Transformers CS231n Lecture Note VII: Recurrent Neural Networks Uncovering Batch & Layer Normalization CS231n Lecture Note VI: CNN Architectures and Training CS231n Lecture Note V: Convolution Neural Networks Basics Demystifying Softmax Loss: A Step-by-Step Derivation for Linear Classifiers Backpropagation: A Vector Calculus Perspective CS231n Lecture Note IV: Neural Networks and Backpropagation CS231n Lecture Note III: Optimization CS231n Lecture Note II: Linear Classifiers CS231n Lecture Note I: Image Classification CSAPP Cache Lab II: Optimizing Matrix Transposition CSAPP Cache Lab I: Let's simulate a cache memory! CS188 Search Lecture Notes III CS188 Search Lecture Notes II How to Use TouchID for Sudo Commands on macOS CS188 Search Lecture Notes I RECAP2025: 留白 CSAPP Bomb Lab 解析 x64 暫存器速查表 CSAPP Data Lab 解析 矩陣的 Modified Gram Schmidt 方法 聊一聊位掩碼(Bit Mask) 整數溢位與未定義行為 快速排序 幾種劃分方法討論 等待 記夢(DeepSeek 輔助創作) 午夜飛行 橋樑 黎明 或 2012 RECAP2024: 水檻臥聽雨 太陽、潮落 RECAP2023: 泡沫 題解 P1622 釋放囚犯 題解 P5888 傳球遊戲 殘陽似火 再會 飢餓藝術家 卡夫卡 Python 中的 zip() 和 enumerate() 泡沫 “救救孩子……”——談魯迅和《狂人日記》 想念 淺灘 蟬 · 夏 微風 觀星 浮塵 復活 【摘錄 | 轉載】普魯斯特 《追憶似水年華》第一卷 《在斯萬家那邊》(一) Time - Pink Floyd - The Dark Side of the Moon 【轉載】靜夜思變調 高樓 幻夢 冰 RECAP2022: 流星雨 清夜 割點 Tarjan 演算法 P3147 USACO16OPEN 262144 P 題解 P3354 Riv 河流 題解 馬拉車演算法 夜雨 層霧 從愚人節玩笑到真的玩笑(bushi): 淺談 lsnotes I made my own Hexo theme 題解 紀念品分組 如何高效使用搜尋引擎 用 GitHub Actions 格式化 C/C++ 程式碼 四季的天空 洛谷 7 月月賽 Div.2 總結 題解 最近公共祖先 (LCA) 用簡單的物理方法證明牛頓萊布尼茨公式 簡評榮耀手環6 海上生明月,天涯共此時。 我為什麼重新拿出了 iPod Swift 中的 SharedPreferance —— UserDefaults 凝視那一輪明月 用 GitHub Actions 部署 Hexo 部落格 遲來的日誌 - WWDC 2020 獎學金 vcpkg - 方便的 C/C++ 庫管理器 vimrc 配置指南 NextCloud - DIY NAS 解決方案 sudo shutdown -r now sudo shutdown -r now
題解 導彈攔截
Louis C Deng · 2021-10-02 · via Louis C Deng's Blog

快要 CSP-S2 了,複習一下一些演算法(弄文化課弄了好久了,很多東西都要忘了。。。

讀題

題目連結: Luogu P1020

資料是這樣的:389 207 155 300 299 170 158 65

推一推,我們發現,389 300 299 170 158 65是第一問的答案;在 155->300的時候,要使用另外一顆炮彈了,故最少應該配備兩套。

在草稿紙上面推一推,不難發現,這道題的兩小問,就是讓你求一個不上升序列長度和一個上升序列長度

預備知識

在求這兩個東西之前,需要先學習STL中的兩個函式:lower_bound upper_bound

其中, lower_bound 是求序列中第一個大於等於某個數的數;upper_bound 是求序列中第一個大於某個數的數。這兩個函式返回的是指標

它們使用的前提是 序列是有序的。

以lower_bound為例,具體用法類似:

1
2
3
int a[100];

lower_bound(a, a+len, x);

這一函式預設是求升序序列中符合條件的數,如果要改為降序序列,則需要一個 cmp 函式,這一點類似於 sort。比如:

1
2
3
int a[100];

lower_bound(a, a+len, x, std::greater<int>());

解題

我的 AC 程式碼

本題有兩種演算法,O(n)O(n)O(nlogn)O(nlogn)。這裡只講後者。

不上升序列

我們用陣列d1當作棧來儲存它。

遍歷導彈高度,把棧頂元素和高度比較:

  1. ai<=dlena_i <= d_len,此時aia_i是符合要求的,直接入棧。
  2. ai>dlena_i > d_len,此時aia_i把棧內第一個小於它的覆蓋掉。這裡說一下,能夠覆蓋它是因為我們不需要再訪問它的值了。在測試資料中,此後幾次都會進行這一操作,如果僅僅取這幾個資料,最長不上升子序列長度仍然正確; 取所有資料,幾次操作之後,就會執行操作1,結果仍然正確。

上升序列

和不上升序列一樣,只不過把 upper_bound 改為了 lower_bound,因為會出現兩個相同高度的導彈的情況,這兩個導彈僅僅需要同一的炮彈去攔截。

程式碼

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 <algorithm>
#include <iostream>

using namespace std;

int ARR[100001];
int n = 0;
int d1[100001];
int c1 = 0;
int d2[100001];
int c2 = 0;

int main() {
while (cin >> ARR[n]) n++;
d1[0] = ARR[0];
d2[0] = ARR[0];
for (int i = 1; i < n; i++) {
if (ARR[i] <= d1[c1])
d1[++c1] = ARR[i];
else {
int j = upper_bound(d1, d1 + c1, ARR[i], greater<int>()) - d1;
d1[j] = ARR[i];
}
if (ARR[i] > d2[c2])
d2[++c2] = ARR[i];
else {
int j = lower_bound(d2, d2 + c2, ARR[i]) - d2;
d2[j] = ARR[i];
}
}
cout << c1 + 1 << endl << c2 + 1 << endl;
return 0;
}

結語

能力有限,如有疏漏,請諒解並補充,謝謝。