Child count off problem
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 10423 |
|
Accepted: 4824 |
Description
There are n children in a circle, to them from the beginning of 1 numbered, is designated from the beginning of the first number of W, check the first S, the child out of the way, and then from the next child began to count, is still reporting s a out, so repeat, until all the children are out (the total number of less than s), the Order of
Input
Number of children entered in the first row N (n<=64)
Next, enter a child's name in each line (no more than 15 characters)
Last line Input w,s (W < N), with comma "," interval
Output
Output a child by person's name in the order in which they are ordered, each line outputs a name
Sample Input
5xiaomingxiaohuaxiaowangzhangsanlisi2,3
Sample Output
Zhangsanxiaohuaxiaomingxiaowanglisi
#include <stdio.h> #include <string.h> #include <iostream> #include <string> #include < Algorithm>using namespace Std;char s[66][20];int main () {int i;int n;int dd, ff;scanf ("%d", &n); for (i=1; i<=n; i + +)//To be saved starting from 1, in order to match the numbering starting from 1 {scanf ("%s", S[i]);} scanf ("%d,%d", &dd, &FF); bool Vis[66];memset (Vis, false, sizeof (VIS)); int cnt=0; The counter when the number to FF was kicked out of int ans=n; The total number of variables, when the total number of deletions gradually reduced to 0 time to jump out of the loop for (I=DD; i++)//Starting from seven o'clock cycle {if (!vis[i])//If the small Hai number is not accessed, the description is still in the loop table, counting +1{cnt++;if (cnt== FF)//if the counter ==ff{vis[i]=true;//This person marks access to be kicked out of the cnt=0;//counter to 0printf ("%s\n", s[i]);//Output the child's name ans-=1;//total -1if (ans==0)// If the total ==0, it should also jump out of the loop, because all the people have already visited {break;}} if (i==n) {i=0;//Q What I return to 0 instead of 1? Don't forget that every trip to this for loop will eventually //execute a step i++, will i=0, in the execution i++,i will return to 1! }}return 0;}
POJ 3750 Child count off problem (linear table thought Joseph problem Array simulation operation of the useless loop linked list, control the subscript point is very easy)