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的更多相关文章
随机推荐
- PAT 甲级 1022 Digital Library
https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336 A Digital Library cont ...
- 使用Java语言递归删除目录下面产生的临时文件
背景:项目copy的过程中,在项目的目录文件夹下面都产生了一个固定的文件,很是讨厌.手动删除的话比较费力,所以写了一个简单的Java程序去删除: public static void main(Str ...
- 使用AutoMapper实现Dto和Model的自由转换(下)
书接上文.在上一篇文章中我们讨论了使用AutoMapper实现类型间1-1映射的两种方式——Convention和Configuration,知道了如何进行简单的OO Mapping.在这个系列的最后 ...
- MVC 锚点
MVC 锚点 linkText:生成的链接所显示的文字 actionName:对应控制器的方法 routeValues:向对应的action传递的参数 controlName:指定控制器的名称 htm ...
- c++ int转string类型
std::string int2string(int input){ std::ostringstream ss; //clear string //ss.str(""); //s ...
- Problem A: 种树 解题报告
Problem A: 种树 Description 很久很久以前,一个蒟蒻种了一棵会提问的树,树有\(n\)个节点,每个节点有一个权值,现在树给出\(m\)组询问,每次询问两个值:树上一组点对\((x ...
- luogu2048 [NOI2010]超级钢琴 (优先队列+主席树)
思路:先扫一遍所有点作为右端点的情况,把它们能产生的最大值加到一个优先队列里,然后每次从优先队列里取出最大值,再把它对应的区间的次大值加到优先队列里,这样做K次 可以用一个前缀和,每次找i为右端点的第 ...
- Python Socket函数及说明
- Oracle数据库--PL/SQL存储过程和函数的建立和调用
1.存储过程建立的格式: create or replace procedure My_Procedure is begin --执行部分(函数内容); end; / 例子:(以hr表为例) crea ...
- 【洛谷P1272】道路重建
题目大意:给定一个 N 个节点的树,求至少剪掉多少条边才能使得从树中分离出一个大小为 M 的子树. 题解:考虑树形 dp,定义 \(dp[u][i][t]\) 为以 u 为根节点与前 i 个子节点构成 ...