[Problem]
There is a set of numbers, from 1 to n, which reduces the number of three, the order is also disrupted, placed in an array of n-3
Please find the missing number. It is better to have a program, and the best algorithm is faster.
Suppose n = 10000
[Solution]
Method 1:
/* There is a set of numbers, from 1 to n, which reduces the number of 3, the order is also disrupted, put in an array of n-3 please find out the Lost number, it is best to have a program, the best algorithm is faster. Suppose n = 10000. Suppose there is an array. A [N-3] method: space to time open an array int.
B [N + 1] and initialize to 0 to traverse array A. For example, if A [I] = 250, B [250] = 1 until array A is traversed, then the Lost number is on B [x] = 0, and then traverse array B to find B [x] = 0, B [y] = 0, B [z] = 0. then the efficiency of x, y, and z is n */
<Pre name = "code" class = "cpp"> void missnum (int A, int n-3)
{
Int B [n + 1] = {0 };
For (int I = 0; I <n-3; I ++)
{
B [A [I] = 1;
}
For (int I = 1; I <n + 1; I ++)
{
If (B [I]! = 1)
Printf ("% d", I); // number of output loss
}
}
From here I am