![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Algorithm
文章平均质量分 75
liukaipeng
对解决挑战性的问题充满激情
具有很强的学习能力
富于创新精神
喜欢在与他人的合作中完善自我,达成目标
工作极具负责心及自信心
待人诚恳,为人正直
展开
-
UVa Problem Solution: 10006 - Carmichael Numbers
Compute the remainder with the following equation: (x*y)%n = (x%n)*(y%n)%nCode:/*************************************************************************** * Copyright (C) 2008 by Liu Kaipeng原创 2008-12-23 12:06:00 · 1787 阅读 · 0 评论 -
UVa Problem Solution: 10127 - Ones
We can solve this problem by simulating the calculating process of multiply two numbers on the paper, yet weve already known the product. We guess the least significant digit of one number, multiply原创 2008-11-24 14:57:00 · 1897 阅读 · 0 评论 -
UVa Problem Solution: 10202 - Pairsumonious Numbers
The problem is not as difficult as it is seen at first. Carefully examine the structure of the sums will give you the key inspiration.Let N[0..n] denotes the n numbers and S[0..n*(n-1)/2] denote the p原创 2008-11-25 17:28:00 · 3044 阅读 · 0 评论 -
UVa Problem Solution: 10105 - Polynomial Coefficients
The coefficient of x1n1x2n2...xknk is (n, n1)(n-n1, n2)...(n-n1-n2-...-nk-1, nk) = n!/n1!n2!...nk!.Code:/************************************************************************* * Copyright (C) 2008原创 2008-11-24 18:48:00 · 1295 阅读 · 0 评论 -
UVa Problem Solution: 701 - The Archaeologist's Dilemma
Let P denotes the prefix, T denotes the # of lost digits. We are searching for N, that the prefix of 2^N is P. We have an inequlity of P*10^T thus log2(P*10^T) which is log2(P)+T*log2(10) Als原创 2008-11-24 13:29:00 · 2890 阅读 · 0 评论 -
UVa Problem Solution: 10035 - Primary Arithmatic
Simple problem. Just count it.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng * * liukaipeng at原创 2008-11-23 18:05:00 · 966 阅读 · 0 评论 -
UVa Problem Solution: 10090 - Marbles
This problem requires us to find two non-negative numbers m1 and m2 that satisfying n1*m1 + n2*m2 = nand minimize the cost c = c1*m1 + c2*m2. First, we can use extended Euclids algorit原创 2009-01-19 18:56:00 · 4321 阅读 · 1 评论 -
UVa Problem Solution: 10018 - Reverse and Add
Do what you are told to do.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng * * liukaipeng at gma原创 2008-11-24 10:28:00 · 932 阅读 · 0 评论 -
UVa Problem Solution: 10191 - Longest Nap
Quite simple question. I add two sentinels to avoid boundary checks. However, the input format is tricky to handle. At first, I use scanf("%2d:%2d %2d:%2d%*[^/n]/n, ...) to read the input. After some原创 2008-11-20 16:58:00 · 1885 阅读 · 1 评论 -
UVa Problem Solution: 10138 - CDVII
Sort the the photo records according to license number, then time. If a license has no cost, do not output it.Code:/************************************************************************* * Copyrigh原创 2008-11-21 13:33:00 · 2256 阅读 · 0 评论 -
UVa Problem Solution: 10026 - Shoemaker's Problem
Simply sort will do the job. Given to jobs, j1 and j2. which should be done first? Do j1 first will cause a total fine to j2 of j1.time * j2.fine and do j2 first will cause a total fine to j1 of j2.ti原创 2008-11-20 18:06:00 · 2119 阅读 · 0 评论 -
UVa Problem Solution: 10037 - Bridge
Given the two fastest people as f1 and f2, f1 1) f1, f2 go --> f1 back --> s1, s2 go --> f2 back: time1 = f2 + f1 + s2 + f2 2) f1, s1 go --> f1 back --> f1, s2 go --> f1 back: time2 = s1 + f1 + s2原创 2008-11-20 14:19:00 · 3035 阅读 · 0 评论 -
UVa Problem Solution: 10194 - Football (aka Soccer)
Nothing worthy to mention.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng * * liukaipeng at gmai原创 2008-11-21 19:14:00 · 2002 阅读 · 0 评论 -
UVa Problem Solution: 847 - A Multiplication Game
We can easily observe that if the drawn number is in range [2, 9], Stan will win, and if it is in range [10, 18], Ollie will win. Suppose that one of Spans win range is [m, n], it can be extend to th原创 2008-11-24 17:44:00 · 2084 阅读 · 0 评论 -
UVa Problem Solution: 10077 - The Stern-Brocot Number System
Just like find a number in a binary search tree. The only trick is keeping record of the current nodes left and right node to get to its child node.Code:/*********************************************原创 2008-11-24 19:39:00 · 1909 阅读 · 0 评论 -
UVa Problem Solution: 10110 - Light, More Light
The final state of the last bulb is determined by the number of factors of n. Only the number which is the square of a number has an odd number of factors, thus it has a state of "yes".Code:/********原创 2008-12-18 13:40:00 · 1588 阅读 · 0 评论 -
UVa Problem Solution: 846 - Steps
Let f(n) denote the furthest distance we can go with n steps, then we can derive this formula easily: f(n) = ((n+1)/2)^2 if n is odd, (1, 2, 3, 4, 3, ,2, 1) f(n) = (n/2)^2 + n/2 if n is even. (1,原创 2008-12-04 21:55:00 · 2313 阅读 · 0 评论 -
UVa Problem Solution: 10049 - Self-describing Sequence
Let g(n) denote the nth number that satifies f(k) > f(k-1). We can know that g(0) = 1, g(1) = 2, g(2) = 4, ... From the definition of g(n), we can know that all the values of f(k) where k belongs原创 2008-12-04 20:01:00 · 3675 阅读 · 1 评论 -
UVa Problem Solution: 10247 - Complete Tree Labeling
Let f(k, d) denote the number of labelings of the k-ary tree of depth d. Moreover, let n(k, d) denote the number of nodes of the tree. The tree contains k subtrees, each contains n(k, d-1) nodes. Ther原创 2008-12-04 00:25:00 · 3809 阅读 · 3 评论 -
UVa Problem Solution: 10254 - The Priest Mathematician
From the description of this problem we can easily draw the recurrence of f(n) = 2*f(n-k) + 2^k - 1and the base cases of f(0) = 0 and f(1) = 1However, how can we determine which k would give the m原创 2008-12-04 13:18:00 · 2914 阅读 · 2 评论 -
UVa Online Jugde Automatic Posting Script
I develop a script to post my code to the UVa online judgeautomatically. This tool will also replace the local #includes withits real content when uploading the code to the server. So, I havent原创 2008-12-03 18:03:00 · 1161 阅读 · 0 评论 -
UVa Problem Solution: 10089 - Repackaging
First, convert each package p = (s1, s2, s3) to a vector (s2 - s1, s3 - s1). All the packages forms convex hull. If point (0, 0) is in this convex hull, then there will be a solution, otherwise not原创 2009-02-13 17:32:00 · 3126 阅读 · 2 评论 -
UVa Problem Solution: 10157 - Expressions
Let n denotes the length of the expression, d denotes the depth at most, and the count is f(n,d). Obviously, f(n,d) = 0 when n is odd. For other conditions, let us consider where we can find the corre原创 2008-12-03 01:20:00 · 2822 阅读 · 0 评论 -
I Love Big Numbers!
My big integer class is finally finished. I have not tested it extensively yet. Anybody who is willing to find a tiny and clearly implemented big number class would find it worthy to have a try. Bug r原创 2008-12-03 01:26:00 · 1114 阅读 · 0 评论 -
UVa Problem Solution: 10198 - Counting
Let f(n) denote the number of ways to make the sum of n. When n > 3, the number of digits is greater than 1. The first digit d used must be one of 1, 2, 3 or 4. Remove the first digit, then the remai原创 2008-11-27 16:36:00 · 3109 阅读 · 0 评论 -
UVa Problem Solution: 10213 - How Many Pieces of Land?
I use this formula to calculate: f(n) = (n,4) + (n,2) + 1. Detailed explanation is available here.I really need to implement a big integer class. The following code is rather ugly.Code:/**************原创 2008-11-26 23:36:00 · 2689 阅读 · 0 评论 -
UVa Problem Solution: 10183 - How many fibs?
The close form of fibs does not help in the problem. The input range is too large that the precision of long double wont be sufficient to handle it correctly. Just generate all the fibs up to 100 dig原创 2008-11-26 15:57:00 · 2496 阅读 · 3 评论 -
UVa Problem Solution: 120 - Stacks of Flapjacks
I just simulate the flipping. We are not required to find the optimal solution, so I choose a way easy to understand. I find the biggest cake in the unsorted stack, and then check its position. If it原创 2008-11-20 11:19:00 · 2190 阅读 · 0 评论 -
UVa Problem Solution: 10152 - ShellSort
Let the required stack to be the sorted sequence, and the original stack to be the sequence to sort. A turtle is numbered by its position in the required stack: the top is 0, the second is 1, and so o原创 2008-11-21 16:42:00 · 1978 阅读 · 1 评论 -
UVa Problem Solution: 10041 - Vito's Family
Vito should live on the street which is the median of his relatives.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng原创 2008-11-18 13:14:00 · 1291 阅读 · 0 评论 -
UVa Problem Solution: 10315 - Poker Hands
I believe sorting the poker at first may be helpful. You should determine the kind of the poker hand from the highest rank down to the lowest. Comparing the poker hands with the same kind is tricky to原创 2008-10-28 14:07:00 · 3009 阅读 · 1 评论 -
UVa Problem Solution: 10038 - Jolly Jumpers
Simple problem. Just record the absolute values of the differences will do the job.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng原创 2008-10-27 17:37:00 · 1640 阅读 · 0 评论 -
UVa Problem Solution: 10050 - Hartals
At the first look, the hartals can be counted with the principle of inclusion and exclusion. However, this may cause the calculations to expand to O(2^numberof(parties)). In another way, simply simula原创 2008-10-29 10:52:00 · 1175 阅读 · 0 评论 -
UVa Problem Solution: 10196 - Check The Check
Checking the kings against others may be faster than checking reversely. I check the knights first and then pawns. All the others are checked by walking along in the eight directions. You must be very原创 2008-10-24 14:53:00 · 2050 阅读 · 0 评论 -
UVa Problem Solution: 10033 - Interpreter
Straight forward simulating.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng * * liukaipeng at gm原创 2008-10-24 14:51:00 · 1959 阅读 · 0 评论 -
UVa Problem Solution: 100 - The 3n+1 problem
I originally used the straight forward method and got a RT of 1.250s. I believe that if I were using Java, I would get a TL. Thus, I switch to the method of precomputing all the cycle-lengths in range原创 2008-10-24 12:36:00 · 2332 阅读 · 2 评论 -
UVa Problem Category
MathGeneral113202256275276294326332347350356374377382386412465471474485498550557568594725727846100061001410019100421006010原创 2008-10-23 16:53:00 · 1299 阅读 · 0 评论 -
UVa Problem Solution: 10142 - Australian Voting
I just simulate the electing process. The RT is very slow.Code:/************************************************************************* * Copyright (C) 2008 by liukaipeng原创 2008-10-24 15:15:00 · 2680 阅读 · 0 评论 -
UVa Problem Solution: 10267 - Graphical Editor
The flood fill algorithm is somewhat tricky to implement. I use a iterative method instead of recursive flooding. I first scan through the west and east points to the current point until a different c原创 2008-10-24 14:18:00 · 1607 阅读 · 0 评论 -
UVa Problem Solution: 706 - LC-Display
Output related problem. I use a predefined bitmap of all the numbers and enlarge them when displaying.Code:/************************************************************************* * Copyright (C) 20原创 2008-10-24 14:09:00 · 1433 阅读 · 0 评论