1. Title Description
According to test instructions, we can know:
Put a ruler on the edge of the table (length L), in order to keep it from falling, extend the maximum length of the desktop edge of 1/2l.
On the basis of the above, and then add a ruler, in order to keep it not falling, extend the edge of the ruler below the maximum length of 1/4l.
In addition to a ruler, in order to keep it from falling, extend the edge of the ruler below the maximum length of 1/6l.
Go down in turn ...
2. Algorithm design
By the above description, we can get a recursive relationship :
When the n ruler is accumulated, the length of the edge of the table extends
Length (0) = 0
Length (n) = Length (n-1) + 1/(2n), n≥1.
3. AC Code
1#include <stdio.h>2 #defineN 1000003 DoubleTable[n];//Table[i] I cards the length of the Extend4 5 voidPrintintn);6 7 intMain ()8 {9 intI, N; Ten //Take table Onetable[0] =0; A for(i =1; i < N; i++ ) - { -Table[i] = table[i-1] +1.0/ (2*i); the } - -printf"# Cards overhang\n"); - while(EOF! = scanf ("%d", &N)) + { - print (n); + } A } at - voidPrintintN) - { -printf"%5d%.3lf\n", N, Table[n]); -}
View Code
USTC OJ-1011 Problem of Deck (combinatorial mathematics, recursive relationship)