HDU4841 round-table questions [worst HDU problem], hdu4841hdu
Round-table problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission (s): 295 Accepted Submission (s): 105
The Problem Description round table is surrounded by 2n people. N of them are good people, and n others are bad people. If the count starts from the first person and reaches the m-th person, the person will be killed immediately. Then, the number starts after the person is killed, and then the m-th person will be killed ...... In this way, people sitting around the Round Table are repeatedly killed. How should we arrange the seats of good people and bad people in advance, so that after killing n people, the rest of the n people sitting in the Round Table are all good people.
Input Multiple groups of data, each group of data Input: Number of good people and bad people n (<= 32767), step m (<= 32767 );
Output: for each group of data, 2n uppercase letters are Output. 'G' indicates good people, 'B' indicates bad people, 50 letters are a row, and blank characters are not allowed. An empty row exists between adjacent data.
Sample Input
2 32 4
Sample Output
GBBGBGGB
The format of SourceAHOI1999 is completely different from that of the question. Dobe has a wonderful question.
#include <stdio.h>#include <string.h>#define maxn 32800bool arr[maxn << 1];int main() {int n, m, i, j, cnt, cas = 0;while(scanf("%d%d", &n, &m) == 2) {memset(arr, 0, sizeof(bool) * n * 2);for(i = j = 0; i < n; ++i) {cnt = 0;while(true) {if(arr[j] == false) {if(++cnt == m) break;}if(++j == 2 * n) j = 0;}arr[j] = true;}for(i = 0; i < n * 2; ++i) {putchar(arr[i] ? 'B' : 'G');if((i + 1) % 50 == 0) putchar('\n');}putchar('\n'); putchar('\n');}return 0;}