hdu 4841圆桌问题

圆桌问题

 思路:其实这道题用vector容器会大大方便很多,但是还是选择了使用while循环,走while循环的话,只需要注意圆桌就行了

代码:

#include<iostream>
#include<cstring>

using namespace std;

int main(){

    int a[100001];
    int m, n, i, cnt, j;

    while (cin >> m >> n){
        cnt = 0;
        i = 0;
        j = m;
        memset(a, 0, sizeof(a));
        while (j){
            if (i == 2 * m)
                i = 0;
            if (a[i] == 0)
                cnt++;
            if (cnt == n){
                a[i] = 1;
                cnt = 0;
                j--;
            }
            i++;
        }
        for (int i = 0; i < 2 * m; i++)
        {
            if (!(i % 50) && i) printf("
");
            if (a[i]) printf("B");
            else printf("G");
        }
        printf("

");
    }
        

    system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/pcdl/p/12349860.html