Joseph ring problem
Time Limit: 1000ms Memory Limit: 65536ktotal Submit: 50 ACCEPTED: 8
Description
Joseph ring problem; N individuals enclose a ring, starting from the first person, reporting the M value exits the ring, and is replaced by his M value instead of the original M value, requiring the output of the left ring.
INPUT
There are 2 numbers, M and N in the first line. (0 OUTPUT Outputs the order of the ring to exit the ring according to the format of the sample. Sample Input 4 6 5 4 2 3 4 2 Sample Output 4, 1, 2, 3, 6, 5 Source This is a universal solution, but for this question, there may be other algorithms, and the high people pass the guides! #include " iostream " #include " CSTDIO " #include " CSTDLIB " Using Namespace std; typedef Struct cnode ... {Int label; int data; struct cnode * next;} CNODE; int M, N, I, Value, J; CNODE * p, * Q; int Main () ... {CIN >> M >> N; cnode * clist; q = (cnode *) malloc (sizeof (cnode)); clist = q; for (i = 1; i <= n; i ) ... {// CIN >> Value; cin >> Value; P = (cnode *) malloc (sizeof (cnode)); // p = new cnode; p-> label = i; p-> data = value; p-> next = NULL; Q-> Next = p; q = p; if (i == n) q-> next = clist-> next;} p = clist; // cout << p-> label << endl; for i = 1; i <= n; i ) ... {for (j = 1; j Array solving method: Source #include < iostream > Using Namespace STD; int Main () ...