Diverse Garland CodeForces - 1108D (贪心+暴力枚举)

You have a garland consisting of nn lamps. Each lamp is colored red, green or blue. The color of the ii-th lamp is sisi ('R', 'G' and 'B' — colors of lamps in the garland).

You have to recolor some lamps in this garland (recoloring a lamp means changing its initial color to another) in such a way that the obtained garland is diverse.

A garland is called diverse if any two adjacent (consecutive) lamps (i. e. such lamps that the distance between their positions is 11) have distinct colors.

In other words, if the obtained garland is tt then for each ii from 11 to n1n−1 the condition titi+1ti≠ti+1 should be satisfied.

Among all ways to recolor the initial garland to make it diverse you have to choose one with the minimum number of recolored lamps. If there are multiple optimal solutions, print any of them.

Input

The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of lamps.

The second line of the input contains the string ss consisting of nn characters 'R', 'G' and 'B' — colors of lamps in the garland.

Output

In the first line of the output print one integer rr — the minimum number of recolors needed to obtain a diverse garland from the given one.

In the second line of the output print one string tt of length nn — a diverse garland obtained from the initial one with minimum number of recolors. If there are multiple optimal solutions, print any of them.

Examples

Input
9
RBGRRBRGG
Output
2
RBGRGBRGR
Input
8
BBBGBRRR
Output
2
BRBGBRGR
Input
13
BBRRRRGGGGGRR
Output
6
BGRBRBGBGBGRG

题意:给定一个字符串,只包含RGB三个字符,你可以改变某些字符使之这个字符串相邻的字符不相等。
那么我们只需要枚举从第二个字符开始的每一个字符串,判定是否和前面的字符相等,如果相等就改成不和后面字串相等字符,这样消耗就一定最小。
很水的一题,细节看code。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
char s[maxn];
int main()
{
    gg(n);
    scanf("%s",s);
    int ans=0;
    repd(i,1,n-1)
    {
        if(s[i]==s[i-1])
        {
            if(s[i]=='B')
            {
                if(s[i+1]!='R')
                {
                    s[i]='R';
                }else
                {
                    s[i]='G';
                }
            }else if(s[i]=='R')
            {
                if(s[i+1]!='B')
                {
                    s[i]='B';
                }else
                {
                    s[i]='G';
                }
            }else if(s[i]=='G')
            {

                if(s[i+1]!='R')
                {
                    s[i]='R';
                }else
                {
                    s[i]='B';
                }
            }
            ans++;
        }

    }
    printf("%d\n",ans );
    printf("%s\n", s);
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

 

 
  

转载于:https://www.cnblogs.com/qieqiemin/p/10313779.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"noisytwins: class-consistent and diverse lmage generation through stylegans" 是关于通过 StyleGANs 实现类别一致和多样化图像生成的研究。 StyleGAN 是一种生成对抗网络 (GAN) 的变种,用于生成逼真的图像。它通过学习图像的潜在空间表示来生成图像,其中每个点都对应一个唯一的图像。在这项研究中,noisytwins 提出了一种改进的 StyleGAN 模型,旨在生成类别一致且具有多样性的图像。 传统的 StyleGAN 模型通常只能生成与训练数据集类别相似的图像,而无法产生跨类别的多样性。对于一个类别,它通常只能生成该类别中的某一个具体样式的图像。然而,noisytwins 通过引入噪音向量,并通过控制这些向量的方式,将该模型扩展至能够在一个类别内生成多种样式的图像。 通过这种方式,noisytwins 的模型能够生成以同一类别为主题的图像,同时在样式上具有多样性。例如,如果我们以猫为类别,传统的 StyleGAN 模型只能生成某一种具体颜色和纹理的猫图像,而 noisytwins 的模型可以生成多种颜色和纹理的猫图像。 这项研究的意义在于扩展了现有的图像生成技术的应用范围。通过实现类别一致且具有多样性的图像生成,noisytwins 的模型可以在许多领域中有重要的应用,如计算机游戏开发、虚拟现实技术以及艺术创作等。 总之,"noisytwins: class-consistent and diverse lmage generation through stylegans" 是一篇关于利用改进的 StyleGANs 实现具有类别一致性和多样性的图像生成的研究,该研究扩展了现有的图像生成技术,并在多个领域中有广泛的应用潜力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值