A. boys and girls

Source: Internet
Author: User
Time limit per test

1 second

Memory limit per test

256 megabytes

Input

Input.txt

Output

Output.txt

There areNBoys andMGirls
Studying in the class. they shoshould stand in a line so that boys and girls alternated there as much as possible. let's assume that positions in the line are indexed from left to right by numbers from 1NRegion + RegionM.
Then the number of IntegersI(1 digit ≤ DigitILatency <latencyNRegion + RegionM)
Such that positions with indexesIAndIContainer + container 1 contain
Children of different genders (PositionIHas a girl and PositionIPipeline + pipeline 1 has
A boy or vice versa) must be as large as possible.

Help the children and tell them how to form the line.

Input

The single line of the input contains two integersNAndM(1 digit ≤ DigitN, Bytes,MLimit ≤ limit 100 ),
Separated by a space.

Output

Print a lineNRegion + RegionMCharacters. print onI-Th
Position of the Line Character "B", ifI-Th
Position of your arrangement shocould have a boy and "g", if it shocould have a girl.

Of course, the number of characters "B" shoshould equalNAnd
The number of characters "G" shoshould equalM.
If there are multiple optimal solutions, print any of them.

Sample test (s) Input
3 3
Output
GBGBGB
Input
4 2
Output
BGBGBB
Note

In the first sample another possible answer is bgbgbgbg.

In the second sample answer bbgbgb is also optimal.

Solution Description: N boys and M girls stand in teams, so that the two adjacent locations have the most occurrences of different gender. This problem can be solved with the greedy method. First, let the previous situation alternate with men and women, and finally add a large number of people. It should be noted that, if there are many boys, the alternating condition is bgbg... gbbb. This is more than gbgb... BBBB, and the case is similar if there are many girls.

The question is file input and output.

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main() {int n,m;int min;int i,flag;freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);cin>>n>>m;if(n>m){min=m;flag=1;}else{min=n;flag=2;}if(flag==1){for(i=0;i<min;i++){cout<<"BG";}for(i=min;i<n;i++){cout<<"B";}}else{for(i=0;i<min;i++){cout<<"GB";}for(i=min;i<m;i++){cout<<"G";}}cout<<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.