Python Study Notes-day 4, recursive functions (factorial and tower games), python Study Notes
Today I learned mainly about recursive functions and have tried some small examples. Here I will record them with the factorial and tower of death.
1. factorial Functions
Factorial is very simple, that is, n! = 1x2x3x... xn.
Use a common iteration function to write a factorial. The Code is as follows:
1 def factori
Link Address: http://www.minwt.com/mac/10083.html/comment-page-2Mac» Smart-Move Place»android | 2014/02/12Android is a platform to open, so previously also shared a few Android emulator, but when the first plum dry using Android emulator, the main function is to test the web, see whether the web on the Android phone can work properly, although the Android emulator, You can also play Android app on your computer through Google player Android app, but because it's a simulator, there are limits to
The Tower of Babylon
Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational of the contest, we'll tell you the whole story:
The Babylonians had n types of blocks, and a unlimited supply of blocks of each type. Each type-i blocks is a rectangular solid with linear dimensions . A Block cou
Description Hanoi (also known as Hanoi) is a puzzle toy derived from an ancient Indian legend. When big Brahma created the world, he made three diamond pillars, and stacked 64 gold discs on a pillar from bottom to top in order of size. The great Brahma commanded the Brahman to rearrange the discs from below to the other pillars in order of size. It is also stipulated that the disc cannot be enlarged on the small disc, and only one disc can be moved between the three pillars at a time. Input numb
---restore content starts---1#include 2#include 3 #defineMax (x, y) (() > (y)? ( x):(y))4 intMain () {5 intN;6 inti,j,k;7scanf"%d", n);//Number of layers8K = (n+1) *n/2;//total of all nodes9 int*a = (int*)malloc(sizeof(int) * k);//dynamic Array, recording the number of each nodeTen for(i =0; I //Enter the number of individual nodes Onescanf"%d",a[i]); A } -K-= n;//The first node of the second-lowest level - for(i = k-1, j =0; i>=0; i--){ theA[i] = A[i] + max (a[i+n],a[i
Recursive implementation Hanoi (Python code)Algorithm Description: A,b,c three pillars, with the help of B, the plate above the column moved to CRequirements: The plate must be discharged from top to bottom in order that the large plate cannot be placed on a small plate;
The idea of recursion is to break this goal into three sub goals.Sub Goal 1: Move the front n-1 plate from A to BSub Goal 2: Move the bottom last plate from A to CSub Goal 3: Move the n-1 plate on B to CThen each target is an i
Number of towers
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 22496 accepted Submission (s): 13563
Problem Description When it comes to the DP algorithm, a classic example is the number-tower problem, which is described in this way:
As shown in the number of towers, the request from the top level to the bottom, if each step can only go to adjacent nodes, then the number of nodes through the
Upgrade" button. Here use the Fire Lady as a demonstration.
Enhanced Skills
Skill upgrades Cost gold coins, the main source of gold coins for replicas and sales. As the skill level increases, the amount of gold coins needed to upgrade will also increase. (as shown in the purple box below)
Initially, we had 10 skill points (shown in the Golden box below). Each upgrade of a skill, will consume 1 points of skill points.
After using the last 1 skill points, you can choose to wait 30 minutes to
Hanoi Tower Problem:
from left to right a B C column large plate, small plate on, with the help of B column to move all plates from column A to column C, only one principle: the large plate can only be under the small plate.
If there are 3 plates, large small number, the smaller the more on the top, from the above to the plate in order numbered 1 (small), 2 (Medium), 3 (large), the principle of the following resolution reference to the number here.
Cow Bowling
Time Limit: 1000MS
Memory Limit: 65536K
Total Submissions: 18487
Accepted: 12308
Description the cows don ' t use actual bowling balls when they go bowling. They a number (in the range 0..99), though, and line up in a standard bowling-pin-like triangle like this:
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5Then the other cows traverse the triangle starting from its tip and moving ' dow
topic: give you a pile of squares of the length of the height, let you base a Babel, the tower higher the better. The requirement is that the length of the block below each block is greater than the length a above, and width B is greater than the width B above. (Hangzhou electric on that cottage monkey eat banana and the problem is the original problem) Example 1 in the 10 20 30 can be such the second layer: the first layer of the : Ten + _____
Mengmeng guard defends against all services that respect and protect the use of user privacy. In order to provide you with more accurate and user-friendly services, Alibaba Cloud Waita will use and disclose your personal information in accordance with this Privacy Policy.
However, mengmeng guard anti-DDoS pro is highly diligent and has a duty to treat such information with prudence. Unless otherwise specified in this Privacy Policy, mengmeng guard's defense information will not be disclosed or p
Killing monsters
Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/131072 K (Java/Others)Total submission (s): 107 accepted submission (s): 54Problem descriptionkingdom rush is a popular TD game, in which you shoshould build some towers to protect your kingdom from monsters. and now another wave of monsters is coming and you need again to know whether you can get through it.
The path of monsters is a straight line, and there are n blocks on it (numbered from 1 to n continuously ). bef
Tower III
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)Total submission (s): 3657 accepted submission (s): 1668
Problem description about the end of the 19th century, an intellectual toy was sold in a store in ozhou with three poles on a copper plate, on the leftmost bar, the Tower consists of 64 disks in ascending order. The purpose is to move all the disks on the lef
Data tower Problems
Question: Given a data Tower, the storage format is the lower Triangle Matrix shown below. In this data tower, you can choose to go down or to the right of each node from the top to go to the bottom layer. Find a path to maximize the value and value of the path.
Input example (Data Tower ):
9
12 15
Tower vtime limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2404 accepted submission (s): 1419
Problem description uses 1, 2,..., and N to represent n dishes. It is called Disk 1, Disk 2, and ,.... The number of plates is big. Classic Tower of Hanoi
The question is often used as a typical recursive example. Some people may not know the story of the
Cocos2D: Anti-tower game production Tour (14th)
Battle of towers: turret attacks
The turret is in place? Check. Is the enemy moving forward? Check again-they look like this! It looks like it's time to defeat these guys! Here we place the intelligence in the code of the turret.
Each turret checks whether an enemy is under attack. (The turret can only attack one enemy at a time. if yes, the turret will start to open fire to the enemy until either of the
Remember the tower question mentioned in the previous section? Let's work it out together next.912 1510 6 82 18 9 519 7 10) 4 15The above picture is an example of a tower problem. Each time from the top element, that is, 9, each can go to the next adjacent to the two nodes, such as from 9 down adjacent to 12 and 15,6 down adjacent is 18 and 9. Find a path from the top to the bottom to make the number and ma
Hanoi
Hanoi (Tower of Hanoi) originated from the Hindu legend, the great Brahma created the world when the creation of three gold steel pillars, one of the pillars from the bottom up 64 pieces of gold disc. The great Brahma commanded the Brahman to rearrange the discs from below to the other pillars in order of size. It is also stipulated that the disc cannot be enlarged on the small disc, and only one disc can be moved between the three pill
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.