多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > 綜合技術 > Codeforces Round #386 (Div. 2) D. Green and Black Tea 數論+貪心

Codeforces Round #386 (Div. 2) D. Green and Black Tea 數論+貪心

來源:程序員人生   發布時間:2017-02-04 09:14:49 閱讀次數:2664次

D. Green and Black Tea
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 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 nka and b (1?≤?k?≤?n?≤?1050?≤?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 thata?+?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


Source

Codeforces Round #386 (Div. 2)


My Solution

題意:喝掉n袋茶,其中a袋綠茶b袋紅茶,連續喝相同的茶最多k次,如果可以全喝完則輸出喝茶的序列,如果不能則輸出NO


數論+貪心

char a為個數多的那個茶的字母的代表,同理b為少的那個字母,aa為a的個數,bb為b的個數

首先int realk = aa / (bb + 1); if(realk * (bb + 1) < aa) realk++; 如果 realk > k 則 ans 為 NO;

否則把aa 分成 bb + 1組,int ok = aa % (bb + 1);if(ok == 0){ok = bb + 1;}

從而有ok組是realk個a,剩余的是realk⑴個a,每組間用b隔開。

復雜度 O(n)


#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
typedef long long LL;
const int maxn = 1e6 + 8;

string ans;

int main()
{
    #ifdef LOCAL
    freopen("d.txt", "r", stdin);
    //freopen("d.out", "w", stdout);
    int T = 6;
    while(T--){
    #endif // LOCAL
    ios::sync_with_stdio(false); cin.tie(0);

    LL n, k, a, b;
    cin >> n >> k >> a >> b;
    int aa = max(a, b), bb = min(a, b);
    char x, y;
    if(aa == a){
        x = 'G';
        y = 'B';
    }
    else{
        x = 'B';
        y = 'G';
    }

    int realk = aa / (bb + 1);
    if(realk * (bb + 1) < aa) realk++;

    if(realk <= k){

        //cout << realk << endl;
        int ok = aa % (bb + 1);
        if(ok == 0){
            ok = bb + 1;
        }
        int cnt = 0, oki = 0;
        ans.clear();
        for(int i = 0; i < n; i++){
            if(cnt == realk){
                ans += y;
                cnt = 0;
                oki++;
                if(oki == ok){
                    realk--;
                }
            }
            else{
                cnt++;
                ans += x;
            }
        }
        cout << ans << endl;
    }
    else cout << "NO" << endl;


    #ifdef LOCAL
    cout << endl;
    }
    #endif // LOCAL
    return 0;
}



  Thank you!

                                                                                                                                               ------from ProLights

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 亚洲国产精品嫩草影院久久 | 亚洲欧美日韩高清 | 国内一区二区三区精品视频 | 成人网在线 | 日本高清中文字幕一区二区三区 | 亚洲伊人久久大香线蕉影院 | 欧美亚洲另类在线观看 | 免费视频在线观看网站 | аⅴ中文在线天堂 | 国产尤物 | 中文字幕在线观看一区 | 亚洲精品中文字幕乱码三区一二 | 国产专区自拍 | 女人的天堂网 | 在线亚洲欧洲福利视频 | 日韩亚洲天堂 | 亚洲精品欧美精品中文字幕 | 国产不卡的一区二区三区四区 | 青青草国产免费国产是公开 | 91亚洲国产成人精品性色 | 亚洲国产成人久久综合一 | 亚洲国产欧美日韩一区二区 | 久久久久久久久国产 | 中文字幕在线播放量 | a毛片全部播放免费视频完整18 | 亚洲精品自拍 | 国产欧美中文字幕 | 久久lu| 91性视频 | 永久在线毛片免费观看 | aa一级黄色片| 亚洲精品不卡久久久久久 | 日韩欧美手机在线 | 免费精品美女久久久久久久久久 | 日韩亚州| 久久91精品国产一区二区 | 欧美成人精品一区二三区在线观看 | 波多野衣结在线精品二区 | 国产国语在线播放视频 | 最近最新中文字幕免费大全 | 国产精品欧美亚洲 |