Please go to the following link to view the questions. Because the exercise questions are frequently reproduced on the internet, it seems difficult to find the original source, from which you can select the ones that were earlier:
Informatics (Computer) Olympic Training Questions (intermediate part)
Some answers can be found online. Due to time restrictions, I will not list them one by one.
I think it is a little difficult to do 30th statements today.
An electronic lock is installed in a confidential department. Each of M staff members sends a magnetic card with the unlocked password on the card. To ensure security, at least N people must use their respective magnetic cards at the same time to open the lock. Q: How many features do electronic locks have? How many features do each person have on their magnetic cards? If the feature numbers are represented by lowercase English letters, print the feature numbers of each member's magnetic card, and the total number of features of the output electronic lock is required to be the least. Set 3 <= m <= 7, 1 <= n <= 4, m and n are input by the keyboard, and staff numbers are represented by 1 #, 2. |
For more information, see 2._GroupIntegrationCalculationQuantityLiuRuJiaBlackBooksCourseParts
The above explanation is very clear (Baidu Library 0-point download)
My solution is as follows: (After writing for one morning, I feel dizzy and have not been optimized. Some logic may be unclear. The output result is correct temporarily. Code :: debugging in blocks)
# Include <stdio. h> char table [35] [7] = {0}; char pers [7] [35] = {0}; int m; int N; int factorial (INT integer) {int ret = 1; if (! Integer) {return 1;} while (integer) {RET * = integer --;} return ret;} int combination (int m, int N) {return factorial (m) /(factorial (n) * factorial (m-N);} void init_combination (int n) {int I; for (I = 0; I <n; I ++) {table [0] [I] = 1 ;}} void next_combination (INT num, int N) {int I; int Len = 0; int stop = 0; for (I = 0; I <num; I ++) {If (Table [N] [I] = 0) // currently 0 {If (stop = 0) Len ++;} else if (Le N> 0) // currently 1 Len> 0 {If (stop = 0) {If (Table [N] [I + 1] = 1) // The next item is 1 {table [n + 1] [I-Len] = 1; Table [n + 1] [I] = 0 ;} else // the next item is 0 {table [n + 1] [I] = 0; Table [n + 1] [I + 1] = 1; stop = 1 ;}} else {table [n + 1] [I] = 1 ;}} else // currently 1 Len = 0 {If (Table [N] [I + 1] = 0 & stop = 0) // The next item is 0 {table [n + 1] [I] = 0; Table [n + 1] [I + 1] = 1; stop = 1 ;} else // the next item is 1 {table [n + 1] [I] = 1 ;}}} void se T_person_keys () {int I, j; for (I = 0; I <combination (M, M-n + 1); I ++) {for (j = 0; j <m; j ++) {If (Table [I] [J] = 1) {pers [J] [I] = 'A' + I ;}}} int main (void) {int I, j; int key, person; printf ("an electronic lock is installed in a server department. Each of M staff members sends a magnetic card with the unlocked password on the card. \ N please enter the total number of M (3 <= m <= 7): \ n "); scanf (" % d ", & M); printf (" to ensure security, requires at least N people to use their respective magnetic cards at the same time to open the lock. \ N enter the value of N (1 <= n <= 4): \ n "); scanf (" % d ", & N); Key = combination (m, n-1); printf ("the electronic lock must have at least % d Features \ n", key); person = combination (M-1, N-1 ); printf ("each person's magnetic card must have at least % d Features \ n", person); init_combination (m-n + 1); for (I = 0; I <combination (M, M-n + 1); I ++) {/* clear the "//" of the following five rows to show pick from M (M-N + 1) all combinations of people (represented by binary digits) * // For (j = 0; j <m; j ++) // {// printf ("% d ", table [I] [J]); // printf ("\ n"); next_combination (M, I);} set_person_keys (); for (I = 0; I <m; I ++) {printf ("% d #", I + 1); For (j = 0; j <combination (m, m-n + 1); j ++) {printf ("% C", Pers [I] [J]);} printf ("\ n ");} printf ("the number of letters in each column above is % d, and the remainder of the blank is % d. For each column, you can select % d for each column ", m-N + 1, N-1, n); Return 0 ;}