casyup.me@outlook.com

0%

写好笔记不是一件容易的事情

想想距离上一篇笔记. 我已经咕了一个月了.

已经渐渐丧失当初写笔记的热情了… 期间也看了很多其他人写的笔记(有些写得真的好👌). 也越发体会到要写好. 写得至少之后自己能看懂. 写全面. 是很不容易的一件事情. 首先你得需要对笔记中的东西知根知底. 其次要组织语言. 排版. 最好应用表格和动态图片解释. …

但是! 在下并不是说自己不写了!

只是. emm… 吐槽一下…

言归正传, 今天带来的对于 diffie-hellman key exchange 算法的讨论(那是真的头疼 = =)

Read more »

“I think that it’s extraordinarily important that we in computer science keep fun in computing. When it started out, it was an awful lot of fun. Of course, the paying customers got shared every now and then, and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful, error-free perfect use of these machines. I don’t think we are. I think we’re responsible for stretching them, setting them off in new directions, and keeping fun in the house. I hope the field of computer science never loses its sense of fun. Above all, I hope we don’t become missionaries. Don’t feel as if you’re Bible salesmen. The world has too many of those already. What you know about computing other people will learn. Don’t feel as if the key to successful computing is only in your hands. What’s in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.”

感觉受到了莫大的鼓舞. 尤其是 What’s in your hands, I think and hope, is intelligence: the ability to see the machine as more than when you were first led up to it, that you can make it more.”

PS: 现在正在读 “structure and interpretation of computer programs” . 以上是这本书的前言. 这本书应该是第三次读了. 这次我要认真读完! :)

C++14~C++17

之前我总结过 C++14 的一些东西, 但现在已经 2020 了啊 = =

所以就想着… emm… 虽然项目还是在用 C11 的东西, 连 C14 都没有. 但是! 需求不会留给你学习的时间的!(即使有, 但那对我不成立!) 所以就再看看 C17 的吧(虽然 C20 已经有了, 不过离实现和稳定还有一段时间, 有其他更优先的事情) 顺便对 C14 回顾一下 :happy:

(PS: 这次在下选择了 cppreference 作为参考)

Read more »

Partition Array into Disjoint intervals

我的思维好像固定了 = =…

my solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class Solution {
public:
int partitionDisjoint(vector<int>& A) {
int b = 0, e = A.size() - 1;
int lx = A[b];
while (b < e) {
while (e > b && A[e] >= lx) { --e; }
// A[e] will less than lx

int olx = lx;
while (b < e) {
lx = max(lx, A[++b]);
}
// lx is max[A[0] - A[e]]

if (olx != lx) {
// recalculate
e = A.size() - 1;
}
}

return b + 1;
}
};

lx 是左边已遍历最大值. e 在每次遍历后将会指向一个从右往左第一个小于这个值的下标.

b 的迭代不会重复, 而 e 的迭代是可能重复的, 这是这个解法的瓶颈.

other solution

PS: 以后没有 the best solution 了. 因为很难说一个算法是 best 的. 因为实际的输入不定. 适用于输入的算法也不定. 并且提交里面往往并不是最好的算法. Discuss 里面才有.

参照

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
class Solution {
public:
int partitionDisjoint(vector<int>& A) {
int b = 0, e = 0;
int lx = A[b], rlx = lx;
for (int i = 0; i < A.size(); ++i) {
if (A[i] < lx) {
e = i;
lx = rlx;
} else if (A[i] > rlx) {
rlx = A[i];
}
}

//printf("rlx: %d, lx: %d", rlx, lx);
return e + 1;
}
};

毫无疑问是比我更好的解法.

唯一可能的疑问是每次迭代所使用的条件有些许复杂. 极端条件如: A {1, 2, 3 … } 下. 这个算法会赋值多次.

而我的解法相对会少很多. (这也是我说大多数情况下不存在 best 的原因)

让我反思的是, 我的思维可能出现了僵化. 一开始我想的办法就是首尾逼近的方式. 所以最后的解法也是类似的结构.

这不禁让我想起之前好像在某个视频中看到的片段. 大意是说: 一个侦探在侦破案件时会让自己忘记一些常识性的东西. 因为这常常会误导自己而忽视重要线索. 或许解法也是如此. 经验同时也可能成为阻止你创新的障碍.

所以有时会有”砍掉重学”这种概念. 我应该想办法规避这种情况. 毕竟”不要让你已获得的东西成为你获取其他东西的障碍”是我坚持的理念.

Extended Asm

今天在脉脉上看到了一个很有趣的东西 ( •̀ ω •́ )✧

哦哦, 在连续看了一段时间令人头晕的文档后, 看看这个真是提神呢!

Read more »