my english is poor

给你一列全部站立的骨牌,同时向左或向右推其中的几个

保证推得方式为: 。。。左,右,左,右,左。。。

即不存在两个相邻的又往相同方向推倒的

刚开始是从左往右一个一个遍历,若第一次推的为往左,将它前面的加起来

再根据 L ,R 判断,累加站立的,还有。。。。太麻烦了

写好程序测试数据正确,提交后WA。。。

有想到用数组记下站立的个数,但不知如何实现。。。

百度一下。。。刚开始看不懂代码。。先提交。。AC。。了

代码如下,注释是我自己的理解

#include<stdio.h>
#include<string.h>
char ch[];
int k[]; //标记数组:1 表示倒下,0 表示站立
int main()
{
int n,i;
scanf("%d",&n);
memset(k,,sizeof(k)); //初始化全部站立
scanf("%s",ch+); //数组 ch 从下标 1 开始
for(i=; i<=n; i++)
{
if(ch[i]=='L') //第 i 个字符为 L ,是往左推的
{
for(int j=i; j>; j--) //往左找
{
k[j]=; //先全部推倒
if(ch[j]=='R') //突然发现前面有个往右推的,不中,不能全推倒
{
if((i-j)%==) //若它们中间的骨牌个数为奇数
k[(i-j)/]=; // 将中间那个骨牌扶起
break; //跳出循环,不往前倒了
}
}
}
if(ch[i]=='R') //第 i 个字符为 R 往右推倒
{
for(int j=i; j<=n; j++) //往右找
{
k[j]=; //也先全推倒
if(ch[j]=='L') //突然发现后面有个往左推的
{
if((j-i)%==) //若它们中间的骨牌个数为奇数
k[(j+i)/]=; //将中间那个骨牌扶起
i=j; //再从后面发现的那个往左推的开始找
break; //跳出循环,不能往后推了
}
}
}
}
int cnt=;
for(i=; i<=n; i++) //推完了,累死我了,放松一下,统计统计几个没有战死沙场的
if(!k[i])
cnt++;
printf("%d\n" ,cnt);
return ;
}

CF - 405B - Domino Effect的更多相关文章

  1. CF 405B Domino Effect(想法题)

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

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

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

  3. POJ 1135 Domino Effect(Dijkstra)

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

  4. 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 ...

  5. UVA211-The Domino Effect(dfs)

    Problem UVA211-The Domino Effect Accept:536  Submit:2504 Time Limit: 3000 mSec  Problem Description ...

  6. POJ 1135 Domino Effect (Dijkstra 最短路)

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9335   Accepted: 2325 Des ...

  7. POJ 1135.Domino Effect Dijkastra算法

    Domino Effect Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10325   Accepted: 2560 De ...

  8. zoj 1298 Domino Effect (最短路径)

    Domino Effect Time Limit: 2 Seconds      Memory Limit: 65536 KB Did you know that you can use domino ...

  9. TOJ 1883 Domino Effect

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

随机推荐

  1. 【Robot Framework】robot framework 学习以及selenium、appnium、requests实践(一)

    话说之前自己写了个selenium的自动化框架,然后又研究了下RF,觉得RF这种基于关键字驱动的框架更为容易上手,当然在做一些比较繁琐的验证时,似乎还不是太灵活,不如自己写几行python来的实惠(也 ...

  2. asp.net中当点击按钮时出现grid编辑弹框

    <dx:ASPxButton runat="server" ID="NewGridButton" Text="新增授权" CssCla ...

  3. entityframework 入门-来自微软

    必备条件 要完成本演练,需要安装 Visual Studio 2010 或 Visual Studio 2012. 如果使用的是 Visual Studio 2010,还需要安装 NuGet. 1.创 ...

  4. mysql修改列名字段类型

    mysql> alter table lesson change title title varchar(100) charset utf8;

  5. Flume NG简介及配置

    Flume下载地址:http://apache.fayea.com/flume/ 常用的分布式日志收集系统: Apache Flume. Facebook Scribe. Apache Chukwa ...

  6. Linux C学习笔记07--管道通信

    管道通信属于进程间通信的一种方式,使用方便,但是局限是父进程与子进程间的通信,下面是调试好的代码. 程序父进程创建2个管道,分别用于父进程写数据--子进程读数据和子进程写数据--父进程读数据: #in ...

  7. Ubuntu中vi常用命令

    在Ubuntu中经常需要修改某些文件,这里对vi中的一些常用操作作一下总结. 1.进入vi命令 vi filename: 打开或新建文件,并将光标置于第一行首 进入文件后,处于命令行模式(comman ...

  8. Nop源码分析一

    从Global.asax文件开始逐层分析Nop的架构. Application_Start()方法作为mvc启动的第一个方法. 1,首先初始化一个引擎上下文,如下面的代码: EngineContext ...

  9. 使用sessionStorage、localStorage存储数组与对象(转)

    http://my.oschina.net/crazymus/blog/371757 使用sessionStorage.localStorage存储数组与对象 发表于3个月前(2015-01-26 1 ...

  10. libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname)

    log报错如下: Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated w ...