zoukankan      html  css  js  c++  java
  • hihocoder 1135 : Magic Box

    #1135 : Magic Box

    时间限制:10000ms
    单点时限:1000ms
    内存限制:256MB

    描述

    The circus clown Sunny has a magic box. When the circus is performing, Sunny puts some balls into the box one by one. The balls are in three colors: red(R), yellow(Y) and blue(B). Let Cr, Cy, Cb denote the numbers of red, yellow, blue balls in the box. Whenever the differences among Cr, Cy, Cb happen to be x, y, z, all balls in the box vanish. Given x, y, z and the sequence in which Sunny put the balls, you are to find what is the maximum number of balls in the box ever.

    For example, let's assume x=1, y=2, z=3 and the sequence is RRYBRBRYBRY. After Sunny puts the first 7 balls, RRYBRBR, into the box, Cr, Cy, Cb are 4, 1, 2 respectively. The differences are exactly 1, 2, 3. (|Cr-Cy|=3, |Cy-Cb|=1, |Cb-Cr|=2) Then all the 7 balls vanish. Finally there are 4 balls in the box, after Sunny puts the remaining balls. So the box contains 7 balls at most, after Sunny puts the first 7 balls and before they vanish.

    输入

    Line 1: x y z

    Line 2: the sequence consisting of only three characters 'R', 'Y' and 'B'.

    For 30% data, the length of the sequence is no more than 200.

    For 100% data, the length of the sequence is no more than 20,000, 0 <= x, y, z <= 20.

    输出

    The maximum number of balls in the box ever.

    提示

    Another Sample

    Sample Input Sample Output
    0 0 0
    RBYRRBY            
    4

    样例输入
    1 2 3
    RRYBRBRYBRY
    样例输出
    7

    /**
              题意:给一串有Y B R 组成的字符串,然后如果他们之间的个数差 等与X Y Z 那就消除现在的
                        字符串,直到字符串结束,看容器中最多有多少个字符  刚开始题意理解错了 他们之间
                        的随意差值都等于 X Y Z 都行,并且没有重用的;然后就。。。。。
              做法:枚举
    **/
    #include <iostream>
    #include <string.h>
    #include <stdio.h>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #define maxn 200100
    using namespace std;
    int num[4];
    char ch[maxn];
    int a,b,c;
    bool solve()
    {
        int ax,ay,bx,by;
        bool flag1 = false;
        bool flag2 = false;
        bool flag3 = false;
        for(int i=0; i<3; i++)
        {
            for(int j=i+1; j<3; j++)
            {
                if(abs(num[i] - num[j]) == a)
                {
                    ax = i;
                    ay = j;
                    flag1 = true;
                    break;
                }
            }
        }
        for(int i=0; i<3; i++)
        {
            for(int j=i+1; j<3; j++)
            {
                if(abs(num[i] - num[j]) == b)
                {
                    if(ax == i && ay == j) continue;
                    bx = i;
                    by = j;
                    flag2 = true;
                    break;
                }
            }
        }
        for(int i=0; i<3; i++)
        {
            for(int j=i+1; j<3; j++)
            {
                if(abs(num[i] - num[j]) == c)
                {
                    if(i == ax &&j == ay) continue;
                    if(i == bx && j == by) continue;
                    flag3 = true;
                    break;
                }
            }
        }
        if(flag1 && flag2 && flag3) return true;
        return false;
    }
    int main()
    {
    //#ifndef ONLINE_JUDGE
    //    freopen("in.txt","r",stdin);
    //#endif // ONLINE_JUDGE
        while(~scanf("%d %d %d",&a,&b,&c))
        {
            scanf("%s",ch);
            memset(num,0,sizeof(num));
            int len = strlen(ch);
            int ans = 0;
            for(int i=0; i<len; i++)
            {
                if(ch[i] == 'R') num[0] ++;
                else if(ch[i] == 'B') num[1] ++;
                else num[2]++;
                ans = max(ans,num[0] + num[1] + num[2]);
                if(solve())
                {
                //    cout<<num[0] <<" "<<num[1] <<" "<<num[2] <<endl;
                    memset(num,0,sizeof(num));
                }
            }
            printf("%d
    ",ans);
        }
        return 0;
    }
  • 相关阅读:
    Javascript 高级程序设计(第3版)
    小文笔记
    修改hadoop FileUtil.java,解决权限检查的问题
    编译hadoop遇到maven timeout
    Hadoop Eclipse开发环境搭建
    tcpdump抓包
    Hadoop JobTracker和NameNode运行时参数查看
    Hadoop hostname: Unknown host
    java.io.IOException: Incompatible namespaceIDs
    Hadoop集群搭建
  • 原文地址:https://www.cnblogs.com/chenyang920/p/4556552.html
Copyright © 2011-2022 走看看