HDU 4841: Round Table problem (vector application)

Source: Internet
Author: User
Round Table Issues

Time limit MS Memory limit 32768 KB OS Windows

problem Description

The round table was surrounded by 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, input per group: number of good and bad People N (<=32767), Step m (<=32767); Output

For each set of data, output 2n uppercase letters, ' G ' for good people, ' B ' for bad guys, 50 letters for one line, no whitespace characters allowed. A blank line is left between adjacent data. Sample Input

2 3
2 4 Sample Output

Gbbg

BGGB Problem Solving ideas:

Used to be recursive, this time because of learning STL, it is specially used vector to do. The core code is

no= (no+m-1)%v.size ();
vis[v[no]]=b;
V.erase (V.begin () +no);

Use vector v to store the person's number, the VIS array tag the person's good or bad, each find the bad guy, record number, and delete this element in V
output a bit of a pit, it is not the data between the blank line, but directly after each output after a blank line on the line
Code:

 #include <iostream> #include <string> #include <vector> #include <

Cstring> using namespace std;
const int m=32767+5;

const int g=0,b=1;

int vis[2*m];
    int main () {int n,m,first=1;
        while (cin>>n>>m) {memset (vis,g,sizeof (VIS));

        Vector<int> V (2*n);
        for (int i=0;i<2*n;i++) v[i]=i;
        int no=0;
            for (int i=0;i<n;i++) {no= (no+m-1)%v.size ();
            Vis[v[no]]=b;

        V.erase (V.begin () +no);
            } for (int i=0;i<2*n;i++) {if (i%50==0&&i>0) cout<<endl;
            if (vis[i]==g) cout<< ' G ';

        else cout<< ' B ';
    } cout<<endl<<endl;
} 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.