[关闭]
@xunuo 2017-01-18T13:22:44.000000Z 字数 2033 阅读 925

Green and Black Tea


time limit per test1 second memory limit per test256 megabytes

来源::codeforces 746 D Green and Black Tea

模拟


Description

Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black.

Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once.

Input

The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 105, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n.

Output

If it is impossible to drink n cups of tea, print "NO" (without quotes).

Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black.

If there are multiple answers, print any of them.

Examples

input

5 1 3 2

output

GBGBG

input

7 2 2 5

output

BBGBGBB

input

4 3 4 0

output

NO

题意

有两种字符:'B'和'G',
输入表示总共有n个字符,最多只能有k个连续,a表示字符'G'的个数,b表示字符'B'的个数
解法:定义一个字符型数组s[],以7 2 2 5为列
先判断哪种字符较多:这里B字符较多,先将s数组全部初始化为B,然后再根据K的多少来插入G;

完整代码

  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<algorithm>
  4. using namespace std;
  5. char s[1000000];
  6. int main()
  7. {
  8. int n,k,a,b,flag,flag1;
  9. while(scanf("%d%d%d%d",&n,&k,&a,&b)!=EOF)
  10. {
  11. memset(s,'\0',sizeof(s));
  12. flag1=0;
  13. flag=1;
  14. if(a>b)///'G'字符较多;
  15. {
  16. for(int i=0;i<n;i++)
  17. s[i]='G';///s初始化全为'G';
  18. for(int i=k;i<n;i+=k+1)///在s中插入'B';
  19. {
  20. if(b-flag1>0)
  21. {
  22. s[i]='B';
  23. flag1++;
  24. }
  25. else
  26. flag=0;
  27. }
  28. if(flag==1)
  29. {
  30. for(int i=0;i<n;i++)
  31. {
  32. if(b==flag1)
  33. break;
  34. if(s[i]=='B'||(i>0&&s[i-1]=='B')||(i<n-1&&s[i+1]=='B'))
  35. continue;
  36. s[i]='B';
  37. flag1++;
  38. }
  39. }
  40. }
  41. else
  42. {
  43. for(int i=0;i<n;i++)
  44. s[i]='B';
  45. for(int i=k;i<n;i+=k+1)
  46. {
  47. if(a-flag1>0)
  48. {
  49. s[i]='G';
  50. flag1++;
  51. }
  52. else
  53. flag=0;
  54. }
  55. if(flag==1)
  56. {
  57. for(int i=0;i<n;i++)
  58. {
  59. if(a==flag1)
  60. break;
  61. if(s[i]=='G'||(i>0&&s[i-1]=='G')||(i<n-1&&s[i+1]=='G'))
  62. continue;
  63. s[i]='G';
  64. flag1++;
  65. }
  66. }
  67. }
  68. if(flag==0)
  69. printf("NO");
  70. else
  71. printf("%s",s);
  72. printf("\n");
  73. }
  74. return 0;
  75. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注