【题目链接】 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. Invalid signature file digest for Manifest main attributes

    Solving a Spark error: Invalid signature file digest for Manifest main attributes When using spark-s ...

  2. zabbix中文配置及乱码问题

    1.切换成中文 2.发现有乱码出现 由于zabbix的web端没有中文字库,所以我们使用windows中的字体. 找到简体字的存储位置——copy到桌面或其他位置——上传到zabbix服务器——web ...

  3. HTTP性能测试

    HTTP性能测试 .note-content {font-family: "Helvetica Neue",Arial,"Hiragino Sans GB",& ...

  4. PHP EOF(heredoc)的使用

    <?php /* Heredoc技术,在PHP手册和技术书籍中一般没有详细讲述,只是提到了这是一种Perl风格的字符串输出技术. 目前一些论坛程序和CMS系统使用了这种技术,前不久看一个朋友的P ...

  5. VHDL数据类型转换

    函     数     名                                     功           能 STD_LOGIC_1164包集合          TO_STDLOG ...

  6. javascript学习笔记(1) 简单html语法

    <html> <head><meta http-equiv="content-type" content="text/html" ...

  7. 对手机SD卡的一些操作

    首先要导入外包 log4j-1.2.16.jar 代码如下: package com.car273.util; import java.io.BufferedReader; import java.i ...

  8. Siverlight+WCF+Nhibernate 开发之旅(一)

    最近正在开发sl程序,考虑了很久,参考了一些框架,令人头疼的数据访问层最终选择wcf+nhibernate,至于为什么选择wcf和nh,个人参考了其他的框架感觉这两者结合从开发效率和便捷性方面比其他的 ...

  9. C语言入门(3)——对Hello World程序的解释

    上篇我们写了一个最简单的程序.这个简单的程序包含了很多重要的内容.本篇我们通过这个最简单的Hello World程序逐一讲解C语言程序的一些特点. 打开Visual Studio 2013 通过菜单- ...

  10. [虚拟化/云][全栈demo] 为qemu增加一个PCI的watchdog外设(三)

    我们已经设计了一个基于qemu的watchdog了.下一步工作就是创建一个含有我们的watchdog的虚拟计算机器了. 准备工作: 1. 使用virt-manager或者virsh创建一个虚拟机器. ...