poj2056
寻找向左凸的地方,每个左凸能让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的更多相关文章
随机推荐
- java 多维数据定义
//一维数组定义与输出class less02{ public static void main(String[] args) { int stu[]=new int[]{1,2 ...
- Python [练习题] :字典扁平化
习题:将source字典扁平化,输出为 target 格式的字典.source = {'a': {'b': 1, 'c': 2}, 'd': {'e': 3, 'f': {'g': 4}}}targe ...
- SQL 中LTrim、RTrim与Trim的用法
LTrim.RTrim与 Trim 函数 返回 Variant (String),其中包含指定字符串的拷贝,没有前导空白 (LTrim).尾随空白 (RTrim) 或前导和尾随空白 (Trim).语法 ...
- centos7 登陆报错 grep:write error
出现这个原因是因为磁盘空间满了 通过df -h查看存储空间 发现磁盘空间满了,可以用 find / -type f -size +1000M 查找大于1000M的文件删除 然后找到用rm -rf 命令 ...
- python自动化之excel
import openpyxl wb=openpyxl.load_workbook(r'C:\Users\Administrator\Desktop\sl.xlsx') type(wb) wb.get ...
- Mouse Hunt CodeForces - 1027D(思维 找环)
Medicine faculty of Berland State University has just finished their admission campaign. As usual, a ...
- BZOJ 3624: [Apio2008]免费道路
3624: [Apio2008]免费道路 Time Limit: 2 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 1201 Solved: ...
- 21天实战caffe笔记_第三天
1 深度学习工具汇总 (1) caffe : 由BVLC开发的基于C++/CUDA/Python实现的卷积神经网络,提供了面向命令行.Matlab和Python的绑定接口.特性如下: A 实现了前馈 ...
- shell中exec命令
1.find中的-exec参数 在当前目录下(包含子目录),查找所有txt文件并找出含有字符串"bin"的行 find ./ -name "*.txt" -ex ...
- Spark记录-Scala类与对象小例子
//基类-Person class Person(val na: String, val ag: Int) { //属性 var name: String = na var age: Int = ag ...