【codeforces 510B】Fox And Two Dots
【题目链接】:http://codeforces.com/contest/510/problem/B
【题意】
让你在一个二维的方格里面找环;
两个点有相邻的边它们才是相连的;
有环YES,没环NO
【题解】
写个flood fill,记录之前走的方向是哪个方向就好;
下次不要往回走;
然后如果能够碰到之前走过的点,就说明形成环了.
【Number Of WA】
0
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,0,-1,0,-1,-1,1,1};
const int dy[9] = {0,0,-1,0,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 60;
int n,m,a[N][N],tag[N][N],cnt,now;
char s[N];
bool dfs(int x,int y,int pre)
{
if (x<=0 || x>=n+1||y<=0 || y>=m+1) return false;
if (a[x][y]!=now) return false;
if (tag[x][y]==cnt) return true;
tag[x][y] = cnt;
bool ok = false;
rep1(j,1,4)
if (j!=pre)
{
int tpre = j+2;
if (tpre>4) tpre-=4;
ok = ok|dfs(x+dx[j],y+dy[j],tpre);
}
return ok;
}
int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n),rei(m);
rep1(i,1,n)
{
rei((s+1));
rep1(j,1,m)
a[i][j]=s[j]-'A'+1;
}
rep1(i,1,n)
rep1(j,1,m)
if (tag[i][j]==0)
{
now = a[i][j];
++cnt;
if (dfs(i,j,-1))
return pri("Yes"<<endl),0;
}
pri("No"<<endl);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}
【codeforces 510B】Fox And Two Dots的更多相关文章
- 【codeforces 510D】Fox And Jumping
[题目链接]:http://codeforces.com/contest/510/problem/D [题意] 你可以买n种卡片; 每种卡片的花费对应c[i]; 当你拥有了第i种卡片之后; 你可以在任 ...
- 【codeforces 510C】Fox And Names
[题目链接]:http://codeforces.com/contest/510/problem/C [题意] 给你n个字符串; 问你要怎么修改字典序; (即原本是a,b,c..z现在你可以修改每个字 ...
- 【codeforces 510A】Fox And Snake
[题目链接]:http://codeforces.com/contest/510/problem/A [题意] 让你画一条蛇.. [题解] 煞笔提 [Number Of WA] 0 [完整代码] #i ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
随机推荐
- 换npm yarn的源让install超时去死吧
安装npm install时,长时间停留在fetchMetadata: sill mapToRegistry uri http://registry.npmjs.org/whatwg-fetch处, ...
- codeforces educational round 25
A 出题人不给样例解释...具体程序 #include<bits/stdc++.h> using namespace std; int n; ]; int main() { scanf() ...
- 在eclipse中如何在大量项目中查找指定文件(转载)
转载:http://blog.csdn.net/inowcome/article/details/6699227 在eclipse中如果希望在大量的项目中寻找指定的文件可不是一件轻松的事,还好ecli ...
- 音频处理中的尺度--Bark尺度与Mel尺度
由于人耳对声音的感知(如:频率.音调)是非线性的,为了对声音的感知进行度量,产生了一系列的尺度(如:十二平均律),这里重点说下Bark尺度与Mel尺度.刚开始的时候,我自己也没弄明白这两个尺度的区别. ...
- 02-vue过滤器和键盘修饰符
过滤器 概念:Vue.js 允许你自定义过滤器,可被用作一些常见的文本格式化.过滤器可以用在两个地方:mustache 插值和 v-bind 表达式.过滤器应该被添加在 JavaScript 表达式的 ...
- 微信小程序上传多张图片,及php后台处理
微信小程序上传多张图片,级小程序页面布局直接来代码index.wxml <view class='body' style='width:{{windowWidth}}px;height:{{wi ...
- $P5018 对称二叉树$
problem 一直忘记给这个题写题解了. 这题挺水的吧. 挺后悔当时没写出来. #ifdef Dubug #endif #include <bits/stdc++.h> using na ...
- RAP接口文档的安装
本机环境 系统:CentOS 6.7 64 位 MySQL 5.6 JDK 1.8 Tomcat 8 Redis 3.0.7 Rap 0.14.1 Rap 说明 官网:https://github.c ...
- servlet.txt笔记
javase jdbc ==>java访问数据库html ==>浏览器显示内容,无法把数据提交给后台?==>动态网页技术(servlet)解决前台.后台交互问题动态网页技术:serv ...
- spring boot打包文件后,报错\No such file or directory
现象: 一段代码: ClassLoader loader = XXXUtil.class.getClassLoader(); String jsFileName = loader.getResourc ...