题目链接: 传送门

Domino Effect

time limit per test:1 second     memory limit per test:256 megabytes

Description

Little Chris knows there's no fun in playing dominoes, he thinks it's too random and doesn't require skill. Instead, he decided to play with the dominoes and make a "domino show".
Chris arranges n dominoes in a line, placing each piece vertically upright. In the beginning, he simultaneously pushes some of the dominoes either to the left or to the right. However, somewhere between every two dominoes pushed in the same direction there is at least one domino pushed in the opposite direction.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right. When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces. The figure shows one possible example of the process.
Given the initial directions Chris has pushed the dominoes, find the number of the dominoes left standing vertically at the end of the process!

Input

The first line contains a single integer n (1 ≤ n ≤ 3000), the number of the dominoes in the line. The next line contains a character string s of length n. The i-th character of the string si is equal to

  • "L", if the i-th domino has been pushed to the left;
  • "R", if the i-th domino has been pushed to the right;
  • ".", if the i-th domino has not been pushed.
    It is guaranteed that if si = sj = "L" and i < j, then there exists such k that i < k < j and sk = "R"; if si = sj = "R" and i < j, then there exists such k that i < k < j and sk = "L".

Output

Output a single integer, the number of the dominoes that remain vertical at the end of the process.

Sample Input

14
.L.R...LR..L..

5
R....

1
.

Sample Output

4

0

1

解题思路:

题目保证测试数据(看input加重字眼)保证L 与 L 之间一定有 R,R 与 R 之间一定有L,所以有了这些保证就很好判断了。

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

int main()
{
    int N;
    char str[3005];
    int ans[3005];
    bool flag = true,IsL = false;
    memset(str,0,sizeof(str));
    memset(ans,0,sizeof(ans));
    scanf("%d",&N);
    scanf("%s",str);
    for (int i = 0; i < N; i++)
    {
        if (str[i] == 'L' || str[i] == 'R')
        {
            flag = false;
            if (str[i] == 'L')
            {
                IsL = true;
                break;
            }
            else
            {
                if (str[i] == 'R')
                {
                    IsL = false;
                    break;
                }
            }
        }
    }
    int j = 0,sum = 0,len = 0;
    for (int i = 0; i < N; i++)
    {
        if (str[i] == '.')
        {
            continue;
        }
        else
        {
            ans[j++] = i;
        }
    }
    if (flag)
    {
        printf("%d\n",N);
    }
    else
    {
        len = j;
        sum = 0;
        if (IsL)
        {
            for (int i = 0; i < len - 1; i++)
            {
                if (i%2==0)
                {
                    sum += (ans[i+1]-ans[i]-1);
                }
                else if (i&1)
                {
                    if ((ans[i+1]-ans[i])%2 == 0)
                    {
                        sum++;
                    }
                }
            }
            if (str[ans[len-1]] == 'L')
            {
                sum += (N-ans[len-1]-1);
            }
        }
        else
        {
            sum += ans[0];
            for (int i = 0; i < len - 1; i++)
            {
                if (i&1)
                {
                    sum += (ans[i+1] - ans[i] - 1);
                }
                else if (i % 2 == 0)
                {
                    if ((ans[i+1]-ans[i])%2 == 0)
                    {
                        sum++;
                    }
                }
            }
            if (str[ans[len-1]] == 'L')
            {
                sum += (N-ans[len-1]-1);
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}

CF 405B Domino Effect(想法题)的更多相关文章

  1. CF - 405B - Domino Effect

    my english is poor 给你一列全部站立的骨牌,同时向左或向右推其中的几个 保证推得方式为: ...左,右,左,右,左... 即不存在两个相邻的又往相同方向推倒的 刚开始是从左往右一个一 ...

  2. CF 214B Hometask(想法题)

    题目链接: 传送门 Hometask Time Limit: 2 seconds     Memory Limit: 256 megabytes Description Furik loves mat ...

  3. CF 405C Unusual Product(想法题)

    题目链接: 传送门 Domino Effect time limit per test:1 second     memory limit per test:256 megabytes Descrip ...

  4. [ACM_图论] Domino Effect (POJ1135 Dijkstra算法 SSSP 单源最短路算法 中等 模板)

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

  5. CF 628B New Skateboard --- 水题

    CD 628B 题目大意:给定一个数字(<=3*10^5),判断其能被4整除的连续子串有多少个 解题思路:注意一个整除4的性质: 若bc能被4整除,则a1a2a3a4...anbc也一定能被4整 ...

  6. CF 628A --- Tennis Tournament --- 水题

    CF 628A 题目大意:给定n,b,p,其中n为进行比赛的人数,b为每场进行比赛的每一位运动员需要的水的数量, p为整个赛程提供给每位运动员的毛巾数量, 每次在剩余的n人数中,挑选2^k=m(m & ...

  7. HDU 4972 Bisharp and Charizard 想法题

    Bisharp and Charizard Time Limit: 1 Sec  Memory Limit: 256 MB Description Dragon is watching NBA. He ...

  8. POJ 1135 Domino Effect(Dijkstra)

    点我看题目 题意 : 一个新的多米诺骨牌游戏,就是这个多米诺骨中有许多关键牌,他们之间由一行普通的骨牌相连接,当一张关键牌倒下的时候,连接这个关键牌的每一行都会倒下,当倒下的行到达没有倒下的关键牌时, ...

  9. POJ 1135 Domino Effect (spfa + 枚举)- from lanshui_Yang

    Description Did you know that you can use domino bones for other things besides playing Dominoes? Ta ...

随机推荐

  1. ubuntu mysql 更改IP导致mysql无法启动

    bind-address = 127.0.0.1 => bind-address= 136.129.20.168 IP要这么改 这么改远程连不上,那么需要把这行整行注释掉,重启MYSQL,tel ...

  2. 自己留存:小经验在asp.net 4.5或者asp.net mvc 5解决A potentially dangerous Request.Form value was detected from the client

    以前的解决办法是 <configuration>    <system.web>        <pages  validateRequest="false&q ...

  3. codevs 4543 treap 模板

    type rec=record lc,rc,v,rnd,size,w,fa:longint; end; var n,root,tot,ans,opt,x,i,po:longint; tr:array[ ...

  4. 15-grep 简明笔

    在文件中搜索模式 grep [options] pattern [file-list] 参数 pattern为正则表达式,file-list为grep要搜索的普通文本文件的路径名列表 选项 -c    ...

  5. Mysql 慢查询和慢查询日志分析

    众所周知,大访问量的情况下,可添加节点或改变架构可有效的缓解数据库压力,不过一切的原点,都是从单台mysql开始的.下面总结一些使用过或者研究过的经验,从配置以及调节索引的方面入手,对mysql进行一 ...

  6. C++类功能扩展预留五招

    第一招虚函数 通过派生类来进行功能扩展是基本的面向对象的方式,这种方式大如下: class base { public: virtual ~base(){} virtual void fun() { ...

  7. eclipse下package的命名规范

    Java的包名都有小写单词组成,类名首字母大写:包的路径符合所开发的 系统模块的 定义,比如生产对生产,物资对物资,基础类对基础类.以便看了包名就明白是哪个模块,从而直接到对应包里找相应的实现. 由于 ...

  8. eclipse的插件安装

    如何安装:http://my.oschina.net/linjunlong/blog/126961 插件安装方法:eclipse和myeclipse版本不一样,略有区别 在线安装: 第一种:知道在线安 ...

  9. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  10. mysql union和union all的区别

    union 对两个结果集进行并集操作,重复数据只显示一次 Union All,对两个结果集进行并集操作,重复数据全部显示 工具/原料 mysql 数据库 方法/步骤   student表数据   使用 ...