• Codeforces 626 B. Cards (8VC Venture Cup 2016-Elimination Round)


     
     
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:

    • take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color;
    • take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color.

    She repeats this process until there is only one card left. What are the possible colors for the final card?

    Input

    The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards.

    The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.

    Output

    Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.

    Examples
    Input
    2
    RB
    Output
    G
    Input
    3
    GRG
    Output
    BR
    Input
    5
    BBBBB
    Output
    B
    Note

    In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.

    In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card.

    In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.

    题意就是两种颜色不同的牌合成一个第三种颜色的牌,两种颜色相同的就合成该颜色的牌,问最后可能的颜色是什么。

    要注意一点就是要按字母顺序输出,就是wa在这里了。。。

    有以下几种情况:

    1.只有一张牌,最后就是这张牌的颜色。

    2.两张牌,都是同一种颜色就直接输出了,如果不同就是第三种牌的颜色。

    3.多张牌(>2)

      1)都是同一种颜色就直接输出了。

      2)如果除了一张牌颜色不一样,其他的牌都是一种颜色,最后输出的结果就是这一张牌的颜色和第三种颜色。

      3)如果颜色都有或者只有两种颜色,但是每一种颜色的牌数>1,结果就是三种颜色都输出。

    要按字母顺序输出!!!

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        char str[250];
        int n,b,r,g;
        while(~scanf("%d",&n)){
            scanf("%s",&str);
            b=0;r=0;g=0;
            if(n==1) printf("%c
    ",str[0]);
            else if(n==2){
                    if(str[0]=='B'&&str[1]=='B') printf("B
    ");
                    else if(str[0]=='G'&&str[1]=='G') printf("G
    ");
                    else if(str[0]=='R'&&str[1]=='R') printf("R
    ");
                   else{
                    if((str[0]=='B'||str[0]=='G')&&(str[1]=='B'||str[1]=='G')) printf("R
    ");
                    else if((str[0]=='B'||str[0]=='R')&&(str[1]=='B'||str[1]=='R')) printf("G
    ");
                    else if((str[0]=='G'||str[0]=='R')&&(str[1]=='G'||str[1]=='R')) printf("B
    ");
                   }
            }
            else{
             for(int i=0;i<n;i++){
                if(str[i]=='B') b++;
                if(str[i]=='G') g++;
                if(str[i]=='R') r++;
             }
            if(b==n) printf("B
    ");
            else if(r==n) printf("R
    ");
            else if(g==n) printf("G
    ");
            else if(b+g==n&&b>g&&g==1) printf("GR
    ");
            else if(b+g==n&&b<g&&b==1) printf("BR
    ");
            else if(b+r==n&&b>r&&r==1) printf("GR
    ");
            else if(b+r==n&&b<r&&b==1) printf("BG
    ");
            else if(g+r==n&&g>r&&r==1) printf("BR
    ");
            else if(g+r==n&&g<r&&g==1) printf("BG
    ");
            else printf("BGR
    ");
            }
        }
        return 0;
    }
  • 相关阅读:
    Spring 中的事务操作、注解、以及 XML 配置
    ..OBJLED.axf: Error: L6218E: Undefined symbol EXTI_Init (referred from exti.o). 错误修改
    ADC分辨率
    单片机ADC检测4-20mA电路,以及计算方法
    STM32速度---网页讲解
    转载电子发烧友网---STM32的IO口灌入电流和输出驱动电流
    精密电阻性能
    ..OBJCAN.axf: Error: L6411E: No compatible library exists with a definition of startup symbol __main.
    asp.net---jquery--ajax 实现滚动条滚动到底部分页显示
    柱状图dataLabels 文字格式 以及如何获取柱子的name(名称)属性
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9692670.html
Copyright © 2020-2023  润新知