代码改变世界

错排问题

2010-10-20 12:08 by wansishuang, 551 阅读, 1 推荐, 收藏, 编辑
摘要:方法一:n各有序的元素应有n!种不同的排列。如若一个排列式的所有的元素都不在原来的位置上,则称这个排列为错排。任给一个n,求出1,2,……,n的错排个数Dn共有多少个。递归关系式为:D(n)=(n-1)(D(n-1)+D(n-2))D(1)=0,D(2)=1可以得到:错排公式为f(n) = n![1-1/1!+1/2!-1/3!+……+(-1... 阅读全文

sum of piece

2010-10-20 10:34 by wansishuang, 194 阅读, 0 推荐, 收藏, 编辑
摘要:一个数组,N个正整数,分成x段,找一种分段法,minimize the maximum sum of x pieces,0 < sum of piece < sum all, 在这个区间进行二分http://poj.org/problem?id=3273http://poj.org/bbs?problem_id=3273 阅读全文

ThreadLocal

2010-10-06 22:32 by wansishuang, 400 阅读, 0 推荐, 收藏, 编辑
摘要:rootjavaj2se1.6java.langThreadLocalClass: java.lang.ThreadLocal<T> public class ThreadLocal<T> This class provides thread-local variables. These variables differ from their normal counter... 阅读全文

a zig-zag array

2010-10-05 11:14 by wansishuang, 285 阅读, 0 推荐, 收藏, 编辑
摘要:Produce a zig-zag array. A zig-zag array is a square arrangement of the first N2 integers, where the numbers increase sequentially as you zig-zag along the anti-diagonals of the array. For a graphical... 阅读全文

rectangles overlap

2010-10-03 23:03 by wansishuang, 183 阅读, 0 推荐, 收藏, 编辑
摘要:rectangles are given. As a struct having {bottomleft-x, bottomleft-y, topright-x, topright-y} you are given two rectangles R1, R2? determine if they intersect 阅读全文

sort a stack

2010-10-03 21:55 by wansishuang, 218 阅读, 0 推荐, 收藏, 编辑
摘要:Given a stack S, write a C program to sort the stack (in ascending order).You are not allowed to make any assumptions about how the stack is implemented; the only functions allowed to be used are: Pus... 阅读全文

calculate the size of the new type

2010-10-02 23:14 by wansishuang, 225 阅读, 0 推荐, 收藏, 编辑
摘要:You are given have a datatype, say X in C. Determine the size of the datatype,without declaring a variable or a pointer variable of that type, and, of course without usingthe sizeof operator! 阅读全文

reverse a stack in place using recursion

2010-10-02 23:09 by wansishuang, 233 阅读, 0 推荐, 收藏, 编辑
摘要:Write a C Program to reverse a stack in place using recursion. You can only use the following ADT functions on stack: IsEmpty, IsFull, Push, Pop, Topyou can not use extra stack or any other data struc... 阅读全文

矩阵转换

2010-10-02 22:46 by wansishuang, 219 阅读, 0 推荐, 收藏, 编辑
摘要:You are given a rectangular matrix with odd numbers of rows and columns. Each cell of the matrix contains either 0 or 1. In one move, you can select any one row or column of the matrix and replace all... 阅读全文

Determining if a point lies on the interior of a polygon

2010-10-02 13:51 by wansishuang, 304 阅读, 0 推荐, 收藏, 编辑
摘要:ZZ http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/Determining if a point lies on the interior of a polygonWritten by Paul BourkeNovember 1987Solution 1 (2D)The following is a simple solutio... 阅读全文