codeforces 154 Div2 A

mac2022-06-30  80

A. Boys and Girls time limit per test 1 second memory limit per test 256 megabytes input input.txt output output.txt

There are n boys and m girls studying in the class. They should 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 1 to n + m. Then the number of integers i (1 ≤ i < n + m) such that positions with indexes i and i + 1 contain children of different genders (position i has a girl and position i + 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 integers n and m (1 ≤ n, m ≤ 100), separated by a space.

Output

Print a line of n + m characters. Print on the i-th position of the line character "B", if the i-th position of your arrangement should have a boy and "G", if it should have a girl.

Of course, the number of characters "B" should equal n and the number of characters "G" should equal m. 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 BGBGBG.

In the second sample answer BBGBGB is also optimal.

 

水题, 优先输出多的内一方,之后间隔输出。

附代码:

1 #include<fstream> 2 using namespace std; 3 int main( void) 4 { 5 int b, g, i=0, m; 6 ifstream fin("input.txt"); 7 ofstream fout("output.txt"); 8 fin>>b>>g; 9 m=b+g; 10 if( b>g) 11 { 12 while( i<m) 13 { 14 if( b>0) 15 { 16 fout<<'B'; 17 b--; 18 i++; 19 } 20 if( g>0) 21 { 22 fout<<'G'; 23 g--; 24 i++; 25 } 26 } 27 } 28 else 29 { 30 while( i<m) 31 { 32 if( g>0) 33 { 34 fout<<'G'; 35 g--; 36 i++; 37 } 38 if( b>0) 39 { 40 fout<<'B'; 41 b--; 42 i++; 43 } 44 } 45 } 46 fout<<endl; 47 return 0; 48 }

 

转载于:https://www.cnblogs.com/shadow-justice/archive/2013/01/19/2868081.html

最新回复(0)