“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” . 以上是这本书的前言. 这本书应该是第三次读了. 这次我要认真读完! :)
classSolution { public: intpartitionDisjoint(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 里面才有.