Codeforces Round #566 (Div. 2) B. Plus from Picture
链接:
https://codeforces.com/contest/1182/problem/B
题意:
You have a given picture with size w×h. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:
A "+" shape has one center nonempty cell.
There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.
All other cells are empty.
Find out if the given picture has single "+" shape.
思路:
遍历每一个点,当某个点的上下左右都为时。向四个方向扩展,记录的个数。之后结束遍历。
当某个点可以形成+且的个数等于所有*的个数的时候,YES。
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 1e3 + 10;
const int MOD = 1e9 + 7;
int n, m, k, t;
char pi[MAXN][MAXN];
int main()
{
scanf("%d %d", &n, &m);
getchar();
int sum = 0;
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
scanf("%c", &pi[i][j]);
if (pi[i][j] == '*')
sum++;
}
getchar();
}
bool flag = false;
for (int i = 2;i <= n-1;i++)
{
for (int j = 2;j <= m-1;j++)
{
if (pi[i][j]=='*'&&pi[i-1][j]=='*'&&pi[i][j+1]=='*'&&pi[i+1][j]=='*'&&pi[i][j-1]=='*')
{
flag = true;
sum--;
int tx, ty;
tx = i-1, ty = j;
while (tx >= 1 && pi[tx][ty] == '*')
tx--, sum--;
tx = i, ty = j+1;
while (ty <= m && pi[tx][ty] == '*')
ty++, sum--;
tx = i+1, ty = j;
while (tx <= n && pi[tx][ty] == '*')
tx++, sum--;
tx = i, ty = j-1;
while (ty >= 1 && pi[tx][ty] == '*')
ty--, sum--;
}
if (flag)
break;
}
cerr << endl;
if (flag)
break;
}
if (flag && sum == 0)
printf("YES\n");
else
printf("NO\n");
return 0;
}
Codeforces Round #566 (Div. 2) B. Plus from Picture的更多相关文章
- Codeforces Round #566 (Div. 2)
Codeforces Round #566 (Div. 2) A Filling Shapes 给定一个 \(3\times n\) 的网格,问使用 这样的占三个格子图形填充满整个网格的方案数 如果 ...
- Codeforces Round #566 (Div. 2) C. Beautiful Lyrics
链接: https://codeforces.com/contest/1182/problem/C 题意: You are given n words, each of which consists ...
- Codeforces Round #566 (Div. 2) A. Filling Shapes
链接: https://codeforces.com/contest/1182/problem/A 题意: You have a given integer n. Find the number of ...
- Product Oriented Recurrence(Codeforces Round #566 (Div. 2)E+矩阵快速幂+欧拉降幂)
传送门 题目 \[ \begin{aligned} &f_n=c^{2*n-6}f_{n-1}f_{n-2}f_{n-3}&\\ \end{aligned} \] 思路 我们通过迭代发 ...
- Codeforces Round #566 (Div. 2)题解
时间\(9.05\)好评 A Filling Shapes 宽度为\(3\),不能横向填 考虑纵向填,长度为\(2\)为一块,填法有两种 如果长度为奇数则显然无解,否则\(2^{n/2}\) B Pl ...
- Codeforces Round #566 (Div. 2)C(字符串,SET)
#include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
随机推荐
- 三款功能强大代码比较工具Beyond compare、DiffMerge、WinMerge
我们经常会遇到需要比较同一文件的不同版本,特别是代码文件.如果人工去对比查看,势必费时实力还会出现纰漏和错误,因此我们需要借助一些代码比较的工具来自动完成这些工作.这里介绍3款比较流行且功能强大的工具 ...
- L90
On Motes and Beams 微尘与栋梁 It is curious that our own offenses should seem so much less heinous than t ...
- TF-IFD算法及python实现关键字提取
TF-IDF算法: TF:词频(Term Frequency),即在分词后,某一个词在文档中出现的频率. IDF:逆文档频率(Inverse Document Frequency).在词频的基础上给每 ...
- bzoj4555: 求和sum 快速傅立叶变换
题目大意 给定\(S(n,m)\)表示第二类斯特林数,定义函数\(f(n)\) \[f(n) = \sum_{i=0}^n\sum_{j=0}^iS(i,j)*2^j*(j!)\] 给定正整数\(n, ...
- Scala学习——集合的使用和“_”的一些使用(中)
1.空格加_可以表示函数的原型 命令行代码: scala> def fun1(name:String){println(name)} fun1: (name: String)Unit scala ...
- POCO库中文编程参考指南(7)Poco::Net::DatagramSocket
1 构造函数 创建一个未连接的 IPv4 数据报 Socket: DatagramSocket(); 创建一个指定 IP 类型(IPv4 或 IPv6)的数据报 Socket: explicit Da ...
- shuts down an ExecutorService
shuts down an ExecutorService in two phases, first by calling shutdown to reject incoming tasks, and ...
- java 通过System.getProperties()获取系统参数
转自:https://www.cnblogs.com/ksuifeng/archive/2010/09/25/1834416.html 1.java的System.getProperty()方法可以获 ...
- UGUI笔记
Text中的可以单独指定某些文字的颜色,只需将想要变色的文本放在<color=**></color>之间即可,如“吃<color=#ff7a38>橙色物品</ ...
- <c和指针>学习笔记3之函数和数组
1 函数声明 (1)原型 告诉编译器函数的参数数量和每个参数的类型以及返回值的类型.编译器通过检查原型之后,就可以检查这个函数得调用,从而来确保参数正确,返回值无误. 通用技巧,将原型写在一个头文件当 ...