Uva133-the dole queue

Source: Internet
Author: User
/* Idea: the question is a bit similar to the deformed Joseph ring, but it feels a little troublesome to use the linked list. So I used arrays to simulate every idea at the beginning. Then I saw a good idea on the Internet, I understood it and typed it myself.Code. In this case, we can understand that there is a pile of playing cards on the table as N, which is placed in order, K cards are removed from the left, M cards are removed from the Right, and m cards are removed from the right. When you count from left to end, you need to start from the leftmost card to the right, and the right number is the same as the left number. When the cards on the table are over. */# Include <stdio. h> int queue [25]; void Init (int n) {for (INT I = 1; I <= N; I ++) queue [I] = I ;} int main () {int N, K, M; while (scanf ("% d", & N, & K, & M) {If (! N &&! K &&! M) break; Init (n); int CNT = 0, front = 0, near = n + 1; while (CNT <n) {int C1 = 0, C2 = 0; while (1) {If (queue [Front]! = 0) C1 ++; If (front> N) Front = 0; If (C1 = k) {printf ("% 3d", queue [Front]); CNT ++; break;} front ++;} while (1) {If (queue [near]! = 0) C2 ++; If (near <1) near = n + 1; if (C2 = m) {If (queue [Front]! = Queue [near]) {printf ("% 3d", queue [near]); CNT ++;} break;} near --;} queue [Front] = 0; queue [near] = 0; If (CNT! = N) printf (",") ;}printf ("\ n") ;}return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.