HDU 4841 Round Table question (mock Joseph ring with Vector)

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=4841


Round Table Issues Time limit:3000/1000 MS (java/others) Memory limit:65535/32768 K (java/others) Total Submission (s): 104 Accepted Submission (s): 17

The Problem Description Round table sits around 2n individuals. where n is a good person, and the other n is a bad person. If the number of persons starting from the first person is counted, and the number of persons to m, the person shall be executed immediately, and then the number of persons executed shall be counted, and then the number of individual m will be executed. In this way, people who sit around the table are continually executed.   How to arrange the seats of these good and bad people beforehand, so that after the execution of the n individuals, the remaining n individuals sitting around the table are all good people. Input multiple sets of data, each set of data entered: the number of good and bad People N (<=32767), Step m (<=32767); output for each set of data, outputs 2n uppercase letters, ' G ' denotes a good person, ' B ' for bad guys, 50 letters in one line, no whitespace characters allowed.   A blank line is left between adjacent data. Sample Input

2 3 2 4 Sample Output
GBBG BGGB Source AHOI1999 recommend We have carefully selected several similar problems for you:4896 4895 4894 4 892 4890

The code is as follows:

Using vectors to simulate Joseph ring #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #
Include <vector> using namespace std;
int flag[50017];
Vector<int> v;
	int main () {int n, m;
    int tot, now;
    int i;
        while (~SCANF ("%d%d", &n,&m)) {v.clear ();
        Tot=2*n;
            for (i = 1; I <= tot; i++) {v.push_back (i);
        flag[i]=0; 
        } now=1;
        /*for (i = 0; i < v.size (); i++) {printf ("%d:%d\n", I,v[i]);
            }*/while (Tot > N)//Only looking for bad guys {now+= (m-1); if (now <= tot) {flag[v[now-1]]=1;//calculates//printf starting from 0 (">%d<\n", V[now-1]
                );
                printf ("1:%d\n", * (V.begin () +now-1));
            V.erase (V.begin () +now-1)//delete now = (Now==tot?1:now) marked by flag[];
          } else {Now%=tot;      now = (Now==0?tot:now);
                Flag[v[now-1]]=1;
                printf (">>%d<<\n", v[now-1]);
                printf ("2:%d\n", * (V.begin () +now-1));
            V.erase (V.begin () +now-1)//delete now = (Now==tot?1:now) marked by flag[];
                } tot--;//total minus one} for (i = 1; I <= 2*n; i++) {if (Flag[i])
            printf ("B");
            else printf ("G");
        if (i%50==0) printf ("\ n");
        } if ((2*n)%50!=0) printf ("\ n");
    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.