【题目链接】 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;
}

  

Codeforces 430B Balls Game(Two Pointers)的更多相关文章

  1. codeforces 939E Maximize! 双指针(two pointers)

    E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  2. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

  3. Codeforces C. Maximum Value(枚举二分)

    题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. CodeForces 215B Olympic Medal(数学啊)

    题目链接:http://codeforces.com/problemset/problem/215/B Description The World Programming Olympics Medal ...

  5. CodeForces 993B Open Communication(STL 模拟)

    https://codeforces.com/problemset/problem/993/b 这题不难,暴力就能过,主要是题意太难懂了 题意: 现在有两个人,每个人手中有一对数,第一个人手中的数是n ...

  6. Codeforces 1458E - Nim Shortcuts(博弈论+BIT)

    Codeforces 题目传送门 & 洛谷题目传送门 首先看到这样的题我们不妨从最特殊的情况入手,再逐渐推广到一般的情况.考虑如果没有特殊点的情况,我们将每个可能的局面看作一个点 \((a,b ...

  7. Codeforces Round #516 Div2 (A~D)By cellur925

    比赛传送门 A. Make a triangle! 题目大意:给你三根木棒,选出其中一根木棒增加它的长度,使构成三角形,问增加的长度最小是多少. 思路:签到题,根据样例/三角形性质不难发现,答案就是最 ...

  8. CodeForces - 1059C Sequence Transformation (GCD相关)

    Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...

  9. Codeforces D. Powerful array(莫队)

    题目描述: Problem Description An array of positive integers a1, a2, ..., an is given. Let us consider it ...

随机推荐

  1. php7 install memcached extension

    #download source code package from git $ git clone https://github.com/php-memcached-dev/php-memcache ...

  2. (转载) css实现小三角(尖角)

    在各种网站里面,我们会经常看到类似于这样的尖角:(示例:新浪微博) 它实现的方式有多种,哪种才是最简单的?哪种才是最优秀的?首先我声明一下,我还不清楚这个东西具体叫什么名字(哪位知道还望告知),暂且叫 ...

  3. PHP判断图片是否存在和jquery中load事件对图片的处理

    在公司的图片服务器中,同一个产品一般会存在对应的大图和缩略图.因此,我们在开发手机端的web网站时,默认使用的是产品图片的缩略图,查询数据库时获取的是缩略图的路径.但是,不知什么原因,时不时的,测试的 ...

  4. ListView的简单使用和性能优化

    起源:ListView是Android开发中使用最广泛的一种控件,它以垂直列表的形式显示所有列表项. 创建ListView有两种方式: ☆ 直接使用ListView进行创建. ☆让Activity继承 ...

  5. VHDL testbench 例子,包含向文件中写数据

      LIBRARY ieee; USE ieee.std_logic_1164.ALL; use std.textio.all; use ieee.std_logic_textio.all;   EN ...

  6. Python进阶--GUI编程

    一.图形用户图面(GUI编程) 1. wxpython下载和安装: 下载url: http://wxpython.org/download.php 2.创建示例GUI应用程序 : ①开始需要导入wx ...

  7. Oracle EBS-SQL (BOM-7):检查有BOM无工艺路线的子装配件或成品.sql

    select     msi.segment1,     msi.description,     msi.item_typefrom inv.mtl_system_items_b   msiwher ...

  8. spring mvc 建立下拉框并进行验证demo

    原文出处:http://howtodoinjava.com/spring/spring-mvc/spring-mvc-populate-and-validate-dropdown-example/ 该 ...

  9. 程序猿的量化交易之路(20)--Cointrader之Assert实体(8)

    转载需说明出处:http://blog.csdn.net/minimicall, http://cloudtrade.top 不论什么可交易的都能够称之为Assert,资产.其类代码例如以下: pac ...

  10. javascript DOM,它到底是什么-------Day32

    这一晚上看的我是头疼不已啊,为什么呢? 终究是半路出家,我对javascript的理解仅仅停留在:调用javascript,改变页面样式,元素和实现一些事件的响应,尽管须要的时候可能会用,可是到底使用 ...