摘要: 并查集的程序设计:为了解释并查集的原理,我将举一个更有趣的例子。话说江湖上散落着各式各样的大侠,有上千个之多。他们没有什么正当职业,整天背着剑在外面走来走去,碰到和自己不是一路人的,就免不了要打一架。但大侠们有一个优点就是讲义气,绝对不打自己的朋友。而且他们信奉“朋友的朋友就是我的朋友”,只要是能通过朋友关系串联起来的,不管拐了多少个弯,都认为是自己人。这样一来,江湖上就形成了一个一个的群落,通过两两之间的朋友关系串联起来。而不在同一个群落的人,无论如何都无法通过朋友关系连起来,于是就可以放心往死了打。但是两个原本互不相识的人,如何判断是否属于一个朋友圈呢?我们可以在每个朋友圈内推举出一个比较 阅读全文
posted @ 2011-10-26 21:46 迷茫者的旅途 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 题目来源: USACO 1.1原题目:Broken NecklaceYou have a necklace of N red, white, or blue beads (3<=N<=350) some of which are red,others blue, and others white, arranged at random. Here are two examples for n=29: 1 2 1 2 r b b r b r r b r b b b r r b r r r w r b r w w b b r r b b b b b b r b r r b r b r 阅读全文
posted @ 2011-10-26 21:03 迷茫者的旅途 阅读(237) 评论(0) 推荐(0) 编辑
摘要: 题目来源:USACO 1.1原题目:Friday the ThirteenthIs Friday the 13th really an unusual event?That is, does the 13th of the month land on a Friday less often than on any other day ofthe week? To answer this question, write a program that will compute the frequency thatthe 13th of each month lands on Sunday, Mon 阅读全文
posted @ 2011-10-26 17:21 迷茫者的旅途 阅读(271) 评论(0) 推荐(0) 编辑