寻找向左凸的地方,每个左凸能让S数量-2。上边或下边如果是半个左凸的话则各对应-1

#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std; #define MAX_ROW 205
#define MAX_COLUMN MAX_ROW int row, column;
char grid[MAX_ROW][MAX_COLUMN]; void input()
{
memset(grid, , sizeof(grid));
for (int i = ; i < row; i++)
scanf("%s", grid[i]);
} void work()
{
int direction = -; //1 is right, 0 is left
int s_cnt = ;
int x = ;
int y = ;
while (grid[x][y] != 'S')
y++;
s_cnt++;
while (x < row)
{
if (y != && grid[x][y - ] == 'S')
{
direction = ;
while (y > && grid[x][y - ] == 'S')
y--, s_cnt++;
x++, s_cnt++;
continue;
}
if (y + < column && grid[x][y + ] == 'S')
{
if (direction == -)
s_cnt--;
if (direction == )
s_cnt -= ;
direction = ;
while (y + < column && grid[x][y + ] == 'S')
y++, s_cnt++;
x++, s_cnt++;
continue;
}
x++, s_cnt++;
}
if (direction == )
s_cnt--;
printf("%d\n", s_cnt - );
} int main()
{
while (scanf("%d%d", &row, &column), row | column)
{
input();
work();
}
return ;
}

poj2056的更多相关文章

随机推荐

  1. 第十一周(11.24-12.01)----ptim测试程序运行速度

    我在dos下用ptime指令对分数运算(http://www.cnblogs.com/YangXiaomoo/p/6095583.html)的运行时间进行了测试.测试结果一般都在0.212-0.217 ...

  2. Android 图表

    今天在群里有人提问Android的图表,在网上搜索了一下,在贴吧中看到的回答,说是Trinea整理的开源项目,不知道是不是博客上的Trinea. 将内容记录如下,以备需要时查看. GraphView ...

  3. DevOps简介

    DevOps 是一个完整的面向IT运维的工作流,以 IT 自动化以及持续集成(CI).持续部署(CD)为基础,来优化程式开发.测试.系统运维等所有环节. DevOps的概念 DevOps一词的来自于D ...

  4. 【codeforces666E】Forensic Examination 广义后缀自动机+树上倍增+线段树合并

    题目描述 给出 $S$ 串和 $m$ 个 $T_i$ 串,$q$ 次询问,每次询问给出 $l$ .$r$ .$x$ .$y$ ,求 $S_{x...y}$ 在 $T_l,T_{l+1},...,T_r ...

  5. css后代选择器 .属性 元素 与 元素.属性的区别

    经常看见css的后代选择器是这样的写法: div.class   和 .class div 的形式两者的区别: div.class  是选中的类名为class 的div元素,与直接使用类选择器.cla ...

  6. 洛谷 P2376 [USACO09OCT]津贴Allowance 解题报告

    P2376 [USACO09OCT]津贴Allowance 题目描述 作为创造产奶纪录的回报,\(Farmer\) \(John\)决定开始每个星期给\(Bessie\)一点零花钱. \(FJ\)有一 ...

  7. exgcd模板

    逆元模板P1082 #include <cstdio> #include <algorithm> int exgcd(int a, int b, int &x, int ...

  8. 2:jquery.cookie用法详细解析

    一个轻量级的cookie 插件,可以读取.写入.删除 cookie. jquery.cookie.js 的配置 首先包含jQuery的库文件,在后面包含 jquery.cookie.js 的库文件. ...

  9. Linux命令dd与cp的区别

    原文链接:http://blog.csdn.net/erazy0/article/details/6087554 问:看了一些关于dd和cp的命令,但是我始终无法明白dd和cp之间有什么不同?不是都可 ...

  10. python---django中form组件(1)简单使用和字段了解

    Django中的Form组件功能: 1.对用户请求的验证 2.生成html代码 Form使用:对用户请求进行验证 前端代码: <form action="/f1.html" ...