8VC Venture Cup 2016 - Elimination Round B. Cards(分类讨论)

原创 2016年08月30日 10:38:48
题意:
给出BGR三种颜色给你,有两种操作
(1)相同的两种合为一种
(2)不同颜色两种合成为第三种
问你最后剩下的一个字母可能是什么颜色,将可能的颜色输出。
思路:
这种题目看起来很难,其实想想答案无非就B,G,R三个字母组成,所以就会想到只要B,G,R都为1时就都能表示,所以推广到任意都行,所以我们只要将为0,的情况枚举出来就行了

#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define L(i) i<<1
#define R(i) i<<1|1
#define INF  0x3f3f3f3f
#define pi acos(-1.0)
#define eps 1e-9
#define maxn 1000100
#define MOD 1000000007

int n,m;


int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int t,C = 1;
    //scanf("%d",&t);
    while(scanf("%d",&n) != EOF)
    {
        int a1 = 0,a2 = 0,a3 = 0;
        char c;
        getchar();
        for(int i = 0; i < n; i++)
        {
            scanf("%c",&c);
            if(c == 'B')
                a1++;
            if(c == 'G')
                a2++;
            if(c == 'R')
                a3++;
        }
        if(a1 > 0 && a2 > 0 && a3 > 0)
        {
            printf("BGR\n");
            continue;
        }
        if(a1 == 0)
        {
            if(a2 == 0)
                printf("R\n");
            else if(a3 == 0)
                printf("G\n");
            else
            {
                if(a2 == 1 && a3 == 1)
                    printf("B\n");
                else if(a2 == 1 && a3 > 1)
                    printf("BG\n");
                else if(a2 > 1 && a3 == 1)
                    printf("BR\n");
                else
                    printf("BGR\n");
            }
        }
        else if(a2 == 0)
        {
            if(a3 == 0)
                printf("B\n");
            else if(a1 == 0)
                printf("R\n");
            else
            {
                if(a3 == 1 && a1 == 1)
                    printf("G\n");
                else if(a3 == 1 && a1 > 1)
                    printf("GR\n");
                else if(a3 > 1 && a1 == 1)
                    printf("BG\n");
                else
                    printf("BGR\n");
            }
        }
        else if(a3 == 0)
        {
            if(a1 == 0)
                printf("G\n");
            else if(a2 == 0)
                printf("B\n");
            else
            {
                if(a1 == 1 && a2 == 1)
                    printf("R\n");
                else if(a1 == 1 && a2 > 1)
                    printf("BR\n");
                else if(a1 > 1 && a2 == 1)
                    printf("GR\n");
                else
                    printf("BGR\n");
            }
        }
    }
    return 0;
}


版权声明:随意转载,转载声明出处~

相关文章推荐

8VC Venture Cup 2016 - Elimination Round B. Cards (隐式图DFS)

B. Cards time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

8VC Venture Cup 2016 - Elimination Round-B. Cards(暴力)

B. Cards time limit per test 2 seconds memory limit per test 256 megabytes input s...

8VC Venture Cup 2016 - Elimination RoundB. Cards

B. Cards time limit per test 2 seconds memory limit per test 256 megabytes input s...

8VC Venture Cup 2016 - Elimination Round E. Simple Skewness(枚举+三分)

题目链接:点击打开链接 题意:给你n个数, 要求选若干个数, 使得这些数的平均数减去中位数尽量大。 思路:由于该题没有顺序问题, 排好序之后我们可以枚举中位数, 可以证明, 奇数个数一定比偶数优,...

8VC Venture Cup 2016 - Elimination Round-C. Block Towers(二分或暴力+数学)

C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes i...

8VC Venture Cup 2016 - Elimination Round-A. Robot Sequence(模拟)

A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes ...

8VC Venture Cup 2016 - Elimination Round A. Robot Sequence

A. Robot Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standar...

8VC Venture Cup 2016 - Elimination Round F. Group Projects(DP)

题目链接:点击打开链接 题意:给n个人, 让我们分成若干组, 每组的值是最大值减去最小值, 求所有组的和。 思路:显然, 需要用DP的思想, 但是该题DP设计的非常巧妙, 而且状态转移的情况容易考...

8VC Venture Cup 2016 - Elimination Round总结

A题: A题题目链接 题目描述: A. Robot Sequence time limit per test 2 seconds memory limit pe...

8VC Venture Cup 2016 - Elimination Round C. Block Towers (二分)

C. Block Towers time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:8VC Venture Cup 2016 - Elimination Round B. Cards(分类讨论)
举报原因:
原因补充:

(最多只允许输入30个字)