zoukankan      html  css  js  c++  java
  • Codeforces 430B Balls Game(Two Pointers)

    【题目链接】 http://codeforces.com/contest/430/problem/B

     

    【题目大意】

      祖玛游戏,给出一个序列,表示祖玛球的颜色序列,三个或者以上的球碰在一起就会发生消除,现在有一个颜色为x的球,问最多可以消除多少球。

    【题解】

      消除的球一定是连续的一段,因此我们可以枚举球射入的位置,然后向两边扩展,每次在已扩展的序列两边有三个相同颜色的球才能继续扩展,否则就停止,取每次枚举的最大值就是答案。

    【代码】

    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std; 
    int n,k,x,ans,t[105];
    int main(){
        scanf("%d%d%d",&n,&k,&x);
        for(int i=1;i<=n;i++)scanf("%d",&t[i]);
        for(int i=0;i<=n;i++){
            int L=i,R=i+1,cnt=1,cur=x,preL,preR;
            while(1){
                preL=L,preR=R;
                while(L&&t[L]==cur){L--;cnt++;}
                while(R<=n&&t[R]==cur){R++;cnt++;}
                if(cnt<=2){L=preL;R=preR;break;}else cur=t[L],cnt=0;
            }ans=max(ans,R-L-1);
        }printf("%d",ans);
        return 0;
    }
    

      

  • 相关阅读:
    android flash air 打包工具
    MyEclipse 7.0快捷键大全
    android mp4 videoView
    位图处理
    myeclise10.0下载
    dropdown.js
    back track
    ANE 跨平台 as3 转 objectc android desktop
    jquery 例子
    android 屏蔽 home 2
  • 原文地址:https://www.cnblogs.com/forever97/p/codeforces430b.html
Copyright © 2011-2022 走看看