摘要: 这题简单,但看到analysis里面的这个解法真是囧。We notice that we can start with 0/1 and 1/1 as our ``endpoints'' and recursively generate the middle points by adding numerators and denominators. Each fraction is created ... 阅读全文
posted @ 2010-04-21 08:41 litstrong 阅读(174) 评论(0) 推荐(0)
摘要: 给一个序列,求最少的交换次数使其有序。排序后求置换群的个数,然后每个置换群要交换的最少次数是该个数-1,所以总的交换次数就是n-置换群的个数了。置换群可以O(n)里求得,这里只有3个数值,我用这三个点,建了个图。然后环的总权和就是置换群的个数了,min(map[1][2], map[2][1]) + min(map[1][3], map[3][1]) + min(map[2][3], map[3]... 阅读全文
posted @ 2010-04-21 08:16 litstrong 阅读(205) 评论(0) 推荐(0)