摘要: C behaves in a confusing way when one or both of the operands to % are negative. In fact, different implementations of C can behave differently in such cases. If you rely on one particular behavior, you might be surprised if you move your program to another computer. Toensure that your programs will 阅读全文
posted @ 2012-11-24 23:42 HardWay 阅读(121) 评论(0) 推荐(0) 编辑
摘要: Maths problem.xi means the ith person gives xi coins to the (i - 1)th person.If the first person gvies 2 coins to the second and the second gives 3 coins to the first, then x2 is = 3 - 2 =1.And what we want to solve is how to make answer =∑abs(x[i]) is the least.average = total_coins / n.So we could 阅读全文
posted @ 2012-11-16 15:40 HardWay 阅读(177) 评论(0) 推荐(0) 编辑
摘要: Job order problem.greedy :Sort the people by their work time decreasingly. And that's the order.The total time is max {start_time[i] + work_time[i]}Demonstration:Assumes that x1x2x3...xixj...xn is the order.If we swap xi,xj, all of the other man's ending time is not changed. (start_time[i] + 阅读全文
posted @ 2012-11-16 15:26 HardWay 阅读(159) 评论(0) 推荐(0) 编辑
摘要: There is no doubt that the strong knight should take care of the strong dragon.So we can sort the knights by their ability increasingly. As for dragon, ditto. From the first knight to the last one, if the knight can kill the current dragon (from the first to the last too), it does. Otherwise, let th 阅读全文
posted @ 2012-11-16 14:56 HardWay 阅读(122) 评论(0) 推荐(0) 编辑