HDU4841 round-table questions [worst HDU problem], hdu4841hdu

Source: Internet
Author: User

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;}



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.