Joseph's ring, poj, 3750, Children Report, problem simulation, poj3750

Source: Internet
Author: User

Joseph's ring, poj, 3750, Children Report, problem simulation, poj3750

Language:DefaultData Report for children
Time Limit:1000 MS   Memory Limit:65536 K
Total Submissions:10071   Accepted:4702

Description

There are N Children in a circle and number them in sequence from 1. Now the number is specified to start from W. When the number is reported to S, the child is listed, next, report the number from the next child, and report the number of S columns. Repeat this until all the children are listed (if the total number is less than S, report the number cyclically.

Input

Number of children in the first line N (N <= 64)
Next, enter the name of a child in each line (the name cannot exceed 15 characters)
Enter W, S (W <N) in the last line, and separate them with commas (,).

Output

Output by person name the children are listed in order, and each row outputs a person's name

Sample Input

5XiaomingXiaohuaXiaowangZhangsanLisi2,3

Sample Output

ZhangsanXiaohuaXiaomingXiaowangLisi

Source


The meaning of the question is not to mention, that is, the General Joseph ring, which requires the output of the circle order, the data is relatively small, N <= 64, directly simulate it.

A variety of small problems, tuned for a long time, too food ~~

Code:

#include <iostream>#include <cstdio>using namespace std;int vis[70];char name[70][20];int n,w,s;int main(){    int i,j;    while (~scanf("%d",&n))    {        memset(vis,0,sizeof(vis));        for (i=0;i<n;i++)            scanf("%s",name[i]);        scanf("%d,%d",&w,&s);        w--;        for (i=1;i<=n;i++)        {            int num=0,a;            while (num<s)            {                if (!vis[w])                {                    a=w;                    w++;                    num++;                }                else                    w++;                w=w%n;            }            printf("%s\n",name[a]);            vis[a]=1;        }    }    return 0;}



Data Report for children

// Define the number of children, tentatively set to 20 # define m 5 // report the number of typedef struct monkey {Joseph Ring problem. Let's explore it by yourself... Joseph's ring problem. Let's explore it on your own. #
 
Data Report for children (using a single-chain table)

# Include <stdio. h>
# Include <stdlib. h>
Struct Node {
Char name [16];
Struct Node * next;
};

Struct Node * head;
Int creatlist (int n)
{
Struct Node * tmp, * p;
Int I = 0;
Head = (struct Node *) malloc (sizeof (struct Node ));
P = head;
For (I = 1; I <= n; I ++)
{
Tmp = (struct Node *) malloc (sizeof (struct Node ));
Scanf ("% s", tmp-> name );
P-> next = tmp;
P = tmp;
}
Tmp-> next = head-> next; // The next pointer of the last node points to the first node.
Return 0;
}

Int outline (int s, int w)
{
Struct Node * p, * q, * o;
Int I;
P = head-> next;
For (I = 1; I <s; I ++) // your code has no major problems, so it may be wrong.
P = p-> next;
While (p-> next! = P)
{
For (I = 1; I! = W; I ++)
{
Q = p;
P = p-> next;
} // Delete the current p
O = p-> next;
Q-> next = p-> next;
Printf ("% s \ n", p-> name );
Free (p );
P = o;
}

Printf ("% s \ n", p-> name );
Free (p );
Free (head );
Return 0;
}

Int main ()
{
Int n, s, w;
Scanf ("% d", & n );
Creatlist (n );
Scanf ("% d, % d", & s, & w );
Outline (s, w );
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.