摘要:
农民约翰有三个容量分别是A,B,C升的桶,A,B,C分别是三个从1到20的整数,最初,A和B桶都是空的,而C桶是装满牛奶的。有时,农民把牛奶从一个桶倒到 另一个桶中,直到被灌桶装满或原桶空了。当然每一次灌注都是完全的。由于节约, 牛奶不会有丢失。描述写一个程序去帮助农民找出当A桶是空的时候,C桶中牛奶所剩量的所有可能性。格式PROGRAM NAME: milk3INPUT FORMAT:(file milk3.in)单独的一行包括三个整数A,B和C。OUTPUT FORMAT:(file milk3.out)只有一行,升序地列出当A桶是空的时候,C桶牛奶所剩量的所有可能性。SAMPLE INP 阅读全文
posted @ 2012-07-18 23:41
AbandonZHANG
阅读(885)
评论(0)
推荐(0)
摘要:
DescriptionGiven a sequence with N integers A(1), A(2), ..., A(N), your task is to find out a sequence B(1), B(2), ..., B(N), such thatV = (|A(1) – B(1)| + |A(2) – B(2)| + ... + |A(N) – B(N)|) + (|B(1) – B(2)| + |B(2) – B(3)| + ... +|B(N-1) – B(N)|)is minimum.InputThe first line in the input contain 阅读全文
posted @ 2012-07-18 23:35
AbandonZHANG
阅读(198)
评论(0)
推荐(0)
摘要:
DescriptionYour rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according t 阅读全文
posted @ 2012-07-18 23:34
AbandonZHANG
阅读(395)
评论(0)
推荐(0)
摘要:
Problem B: Save the Students!Hogwarts is under attack by the Dark Lord, He-Who-Must-Not-Be-Named. To protect the students, Harry Potter must cast protective spells so that those who are protected by the spells cannot be attacked by the Dark Lord.Harry has asked all the students to gather on the vast 阅读全文
posted @ 2012-07-18 23:30
AbandonZHANG
阅读(323)
评论(0)
推荐(1)
摘要:
ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011Problem E: Distinct PrimesArithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and she is better than him at it. Prime numbers are of mystical importance in 阅读全文
posted @ 2012-07-18 23:27
AbandonZHANG
阅读(364)
评论(0)
推荐(0)
摘要:
看哪些书才能渐渐开始精通C++?推荐的阅读顺序:level 1从<<essential c++>>开始,短小精悍,可以对c++能进一步了解其特性以<<c++ primer>>作字典和课外读物,因为太厚不可能一口气看完level 2然后从<<effective c++>>开始转职,这是圣经,请遵守10诫,要经常看,没事就拿来翻翻接着是<<exceptional c++>>,个人认为Herb Sutter主席大人的语言表达能力不及Scott Meyers总是在教育第一线的好顺下来就是<<mo 阅读全文
posted @ 2012-07-18 23:09
AbandonZHANG
阅读(293)
评论(0)
推荐(0)
摘要:
C. Lexicographically Maximum Subsequencetime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou've got strings, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.We'll call a non-empty strings[p1p2.. 阅读全文
posted @ 2012-07-18 23:02
AbandonZHANG
阅读(456)
评论(0)
推荐(0)
摘要:
l Trie原理Trie的核心思想是空间换时间。利用字符串的公共前缀来降低查询时间的开销以达到提高效率的目的。l Trie性质好多人说trie的根节点不包含任何字符信息,我所习惯的trie根节点却是包含信息的,而且认为这样也方便,下面说一下它的性质 (基于本文所讨论的简单trie树)1.字符的种数决定每个节点的出度,即branch数组(空间换时间思想)2. branch数组的下标代表字符相对于a的相对位置3.采用标记的方法确定是否为字符串。4.插入、查找的复杂度均为O(len),len为字符串长度l Trie的示意图如图所示,该trie树存有abc、d、da、dda四个字符串,如果是字符串会在 阅读全文
posted @ 2012-07-18 22:51
AbandonZHANG
阅读(281)
评论(0)
推荐(0)
摘要:
将N!表示成N!=p1^t1*p2^t2*…pi^ti…*pk^tk(其中p1,p2……pk是素数,1<N<=10^6)显然很容易通过素数筛选求出pi,因为1<pi<=N,关键是如何快速地求出ti。我们先来看一下对于2这个素因子,把N!分成两部分,即奇偶两部分假设N是偶数N!=1*2*3*4*5……N=(2*4*6……)*(1*3*5……)因为有N/2个偶数,所以偶数部分可以提出N/2个2,=2^(N/2)*(1*2*3*……N/2)*(1*3*5*……)=2^(N/2)*(N/2)!*(1*3*5*……)看到了吗!神奇的事情发生了,N规模的问题转化成了N/2的问题了。 阅读全文
posted @ 2012-07-18 22:48
AbandonZHANG
阅读(208)
评论(0)
推荐(0)
摘要:
给你n个数,其中有且仅有一个数出现了奇数次,其余的数都出现了偶数次。用线性时间常数空间找出出现了奇数次的那一个数。分析:从头到尾异或一遍,最后得到的那个数就是出现了奇数次的数。这是因为异或有一个神奇的性质:两次异或同一个数,结果不变。再考虑到异或运算满足交换律,先异或和后异或都是一样的,因此这个算法显然正确。 阅读全文
posted @ 2012-07-18 22:47
AbandonZHANG
阅读(255)
评论(0)
推荐(0)

浙公网安备 33010602011771号