摘要:
Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1 ... n. 输出1~n能生成的所有BST。 首先是BST的生成方法。根据BST的特性(若有左子树 阅读全文
摘要:
综合unp前五章,写了一个服务器-客户端程序。 主要功能:客户端从标准输入读入字符串发送到服务器,服务器显示。服务器接受连接后,fork()子进程实现具体操作。 服务器主要过程: socket()->bind()->listen()->accept()->read(),服务器在accept一个cli 阅读全文
摘要:
#include //保留小数点后2位 cout using namespace std; int main() { double val = 10.6; cout << setprecision(2) << val << endl;//保留两位有效数字 cout << setiosflags(ios::fixed) << setprecision... 阅读全文
摘要:
A rectangle is represented as a list [x1, y1, x2, y2], where (x1, y1) are the coordinates of its bottom-left corner, and (x2, y2) are the coordinates 阅读全文
摘要:
惊群效应指的是在生产者和消费者模型中,生产者广播时,使得多个消费者产生响应。 测试:把模拟售票系统的49行改成每次只补一张票。 如果用 if , 结果 当第一次补票的时候,因为是if,所有的4个线程都做出反应,但是实际的票只能满足线程1,所以导致另外3个线程提前退出。 改用while, 结果 con 阅读全文
摘要:
主要用到函数: 程序模拟了4个窗口,一起卖20张票。 实验结果如图: 一些结论: 1、网上对linux下sleep()休眠的是整个进程还是某一个线程的答案不统一,在我的测试环境下(ubuntu 16.04 LTS),发现sleep休眠的是单独线程。理由: 结果中,窗口1每1秒卖一张票,窗口2每2秒卖 阅读全文
摘要:
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 合并k个有序链表。 用归并排序就好了。 阅读全文
摘要:
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set). 求全部子集。 解决:Backtracking问题,主要问题在对重复集合的处 阅读全文
摘要:
Equations are given in the format A / B = k, where A and B are variables represented as strings, and k is a real number (floating point number). Given 阅读全文
摘要:
The set [1,2,3,...,n] contains a total of n! unique permutations. By listing and labeling all of the permutations in order, we get the following seque 阅读全文