CodeForces 1182B Plus from Picture
题目链接:点击这里
题意:
给出一个n*m的图形判断这个图形中是否只有一个+的图案。首先找到一个小十字,然后把他相关的行和列连接的*都变成.
最后再遍历一遍,只要是团只剩下.就对。
AC代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
using namespace std;
int i,j,k,l;
int ans,cnt;
char a[510][510];
int n,m,x,y,c,b;
bool flag1;
int move1[5]={0,0,1,-1};
int move2[5]={1,-1,0,0};
void dfs(int x,int y)
{cnt=0;for(int i=0; i<4; i++){int nx=x+move1[i];int ny=y+move2[i];if(nx>0&&ny>0&&nx<=n&&ny<=m&&a[nx][ny]=='*'){cnt++;}}return ;
}
int main()
{while(~scanf("%d %d",&n,&m)){for(i=1; i<=n; i++)for(j=1; j<=m; j++)cin>>a[i][j];flag1=1;bool flag2=0;for(i=1; i<=n; i++){for(j=1; j<=m; j++){if(a[i][j]=='*'){dfs(i,j);if(cnt==4){a[i][j]='.';flag2=1;for(k=i-1;k>0;k--){if(a[k][j]=='*')a[k][j]='.';elsebreak;}for(k=i+1;k<=n;k++){if(a[k][j]=='*')a[k][j]='.';elsebreak;}for(k=j+1;k<=m;k++){if(a[i][k]=='*')a[i][k]='.';elsebreak;}for(k=j-1;k>0;k--){if(a[i][k]=='*')a[i][k]='.';elsebreak;}break;}}}}for(i=1;i<=n;i++){for(j=1;j<=m;j++){//cout<<a[i][j];if(a[i][j]=='*'){flag1=0;break;}}//cout<<a[i][m]<<endl;}//cout<<flag1<<" "<<flag2<<endl;if(flag1==1&&flag2==1)printf("YES\n");elseprintf("NO\n");}return 0;
}
CodeForces 1182B Plus from Picture相关推荐
- Codeforce 1182B Plus from Picture
题目链接:http://codeforces.com/problemset/problem/1182/B 题意:检查图中 * 形成的是否是唯一的十字. 思路:dfs找到十字的中心,反向消除十字,最后检 ...
- Codeforces Global Round 8 C. Even Picture 题解[巧妙法构造题]
C. Even Picture 题目大意:让你构造一个连通图,图中有k个灰点其中n个点4面都是灰点,(k-n)个点周围2个点是灰点 我们设最上面的为(1,1)点就可以了 ps:exactly:只有,其 ...
- Codeforces Beta Round #14 (Div. 2) B. Young Photographer 水题
B. Young Photographer 题目连接: http://codeforces.com/contest/14/problem/B Description Among other thing ...
- Codeforces Round #528 (Div. 2, based on Technocup 2019 Elimination Round 4) C. Connect Three 【模拟】...
传送门:http://codeforces.com/contest/1087/problem/C C. Connect Three time limit per test 1 second memor ...
- 【Codeforces】 Round #374 (Div. 2)
Position:http://codeforces.com/contest/721 我的情况 开始还是rank1,秒出C.(11:00机房都走光了,我ma到11:05才走,只打了一个小时) 结果.. ...
- Codeforces Round #374 (Div. 2) A. One-dimensional Japanese Crosswor 水题
A. One-dimensional Japanese Crossword 题目连接: http://codeforces.com/contest/721/problem/A Description ...
- Codeforces Round #572 (Div. 2)(ABCD1D2E)
Keanu Reeves CodeForces - 1189A After playing Neo in the legendary "Matrix" trilogy, Keanu ...
- Codeforces Round #172 (Div. 2) C. Rectangle Puzzle 数学题几何
C. Rectangle Puzzle Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/281/p ...
- CodeForces - 1517B Morning Jogging
B. Morning Jogging time limit per test1 second memory limit per test256 megabytes The 2050 volunteer ...
最新文章
- go语言中fmt包中Print、Printf、Println输出相关函数的区别
- 波士顿动力机器人齐秀舞姿,这是要成团出道?
- lLinux网络相关命令,防火墙介绍及相关命令
- MathWorks.MATLAB.NET.Arrays.MWArray”的类型初始值设定项引发异常 解决方法
- android 代码生成 keyhash,android签名 keystore 生成 keyhash
- 原始jdbc操作的分析
- elementUI自定义字体图标
- Java最佳实践– Char到Byte和Byte到Char的转换
- C++ 高级篇(二)—— 名空间 (Namespaces)
- MyBatis系列-Mybatis入门精讲
- cmake的一个编译报错
- Adobe CS3 Design Premium 2DVD完全版(原盘镜像)
- C语言 简单的在线电子词典
- 全志A33N切换分支.repo/repo/repo forall -c git checkout exdroid-7.1.1_r23-a33-v7.0rc2.1
- 【51nod-1521】一维战舰
- python绘制绝对值正弦曲线_Python图形绘制操作之正弦曲线实现方法分析
- 普林斯顿宣布开源 25 核处理器
- postgreSQL数据类型字符串和数值相互转换
- 深度学习相关学术会议
- 转大数据开发,适合什么岗位?