April 26th, 2011几道题(5)
给定两个数组 X 和 Y,它们都包含 n 个元素且都是有序的,如何找到它们的中位数?

Read the rest of this entry »
给定两个数组 X 和 Y,它们都包含 n 个元素且都是有序的,如何找到它们的中位数?

Read the rest of this entry »
Let A and B are sorted array with length m and n respectively, given k, the problem is to find the first k smallest elements which are composed of A[i]+B[j].
e.g.
A={1,3,5,7}, B={2,6, 10}, k = 3
Output: 3 5 7。
Read the rest of this entry »
取值为 [1,n-1] 含 n 个元素的整数数组至少存在一个重复数,O(n) 时间内找出其中任意一个重复数。
如果只有一个重复数,那么好说,直接用数组的和减去 1 到 n-1 的和既可。
Read the rest of this entry »
有两个数组 A 和 B,B 数组中的元素在 A 中连续出现,但是可能它们在 A 中的顺序并不是像 B 中那样的顺序,请找出 B 中元素在 A 出现的开始位置和结束位置。
比如:
A: 4, 1, 6, 2, 8, 9, 5, 3, 2, 9, 8, 4, 6
B: 6, 1, 2, 9, 8
则答案是 (1, 5)。
Read the rest of this entry »
给定数组Arr[n],对于其中的每个元素Arr[i](0=Arr[i],并且i-k值最小(即最靠近)。要求O(n)时间内找出Arr中所有元素对应的Arr[k]的位置。
比如:
[src]: 9, 5, 2, 4, 7
[dst]: -1,0, 1, 1, 0。
思路:借助于栈来实现,从后向前遍历数组,while栈顶元素小于当前遍历的数组元素,则更新dst,并 pop。
Read the rest of this entry »
求一个长度小于100位且满足每位的数字和为s1(< =10000),每位的数字的平方和为s2(<=10000)的最小的数,或判无解。
Read the rest of this entry »
问题描述: 在一个聚会上有 n 个人,其中有一个名人,大家都认识他,但他却不认识所有其他人。现在请你只通过询问来宾 x 是不是认识来宾 y 的方式把这个名人找出来。最多只能使用 O(n) 次询问。
Read the rest of this entry »
求由 n 个1、m 个 0 组成,并且任意前缀中 1 的个数不少于 0 的个数的字符串的个数,并模 20100501。
参考组合数学第 31 页。
http://hi.baidu.com/fzu_saber/blog/item/508911445c740a2fcefca352.html
http://hi.baidu.com/uuriel/blog/item/9752e0f65a7e5b2b720eecce.html
直接利用 gnu gmp 库来搞。
gcc -c bigint.c -I/root/src/mysql-5.1.56/sql -I/root/src/mysql-5.1.56/include -I/root/src/mysql-5.1.56/regex -I/root/src/mysql-5.1.56 -g -O2 -Wall -g -fno-exceptions -shared -fPIC -DPIC -DMYSQL_DYNAMIC_PLUGIN -L/usr/local/mysql/lib -rdynamic -L/usr/local/mysql/lib/mysql -lz -lpthread -lcrypt -lnsl -lm -lpthread -lgmp
gcc -o bigint.so -shared bigint.o -lgmp
Read the rest of this entry »
http://www.cppblog.com/sdfond/category/10266.html
http://hi.baidu.com/acmdearway/blog/category/%D7%E9%BA%CF%CA%FD%D1%A7
http://hi.baidu.com/ofeitian/blog/item/ceb99a614f1f604aebf8f8be.html
connect 默认好像没法控制超时。但是可以将 connect 的描述符设置为非阻塞,然后用 select 来控制的办法。
先 socket,设置为非阻塞,然后调用 connect,如果出错的 errno 是 EINPROGRESS,则调用 select 在描述符上等待可读和可写。
http://sue602.blog.163.com/blog/static/314953072010102422418685/
http://blog.csdn.net/chensichensi/archive/2010/01/28/5264481.aspx
http://www.cnblogs.com/asuran/archive/2009/11/24/1609462.html
http://22andy22.blog.163.com/blog/static/54441693200910373919392/