Method with score (Blue Bridge cup)
Problem description: Score
100 can be expressed as a score:
100 = 3 + 69258/714
It can also be expressed:
100 = 82 + 3546/197
Note: Contains numbers and numbers with scores.
1 ~ 9
Appear separately and only once (excluding 0)
For example, 100 has 11 notation.
Question requirements:
Reads a positive integer from the standard input.
N (N <1000*1000)
The program outputs this number in digital 1 ~ 9. All types of data with scores are composed without repetition.
Note: you do not need to output each representation. Only the number of representations is counted!
For example:
User input: 100
Program output: 11
For example:
User input: 105
Program output: 6
Resource conventions:
Peak memory consumption <64 M
CPU consumption <3000 ms
Ideas:
The problem solved can be converted to n = I + j/k; ---> j = (n-I) * k. It can be solved by brute force solution.
Because a total of 9 digits can be used, k can take up to four digits, and I can take up to n-1.
So the code is as follows (considering that the general test does not use the time test function, the old time measurement function is omitted here );
# Include
// # Include
Int judge (int I, int j, int k) // used to determine whether the three have the same number {int a [11] = {0}, g; while (I> 0) {a [g = I % 10] ++; if (a [g]> 1) // only return 0; i/= 10;} while (j> 0) {a [g = j % 10] ++; if (a [g]> 1) return 0; j/= 10;} while (k> 0) {a [g = k % 10] ++; if (a [g]> 1) return 0; k/= 10;} if (a [0]> 0) // The number range is 1 ~ 9 return 0; for (I = 1; I <= 9; I ++) {if (a [I] = 0) return 0;} return 1 ;} int main () {int n; while (~ Scanf ("% d", & n) {int I, j, k, count = 0; for (I = 1; I <= n-1; I ++) // The maximum I value is n-1 {for (k = 1; k <= 9999; k ++) // k is used as the denominator and the change interval has nine digits, k can be up to four digits {if (I! = K) {j = (n-I) * k; if (judge (I, j, k) count ++; // count for counting }}printf ("% d \ n", count) ;}return 0 ;}