【codeforces 196B】Infinite Maze
【题目链接】:http://codeforces.com/problemset/problem/196/B
【题意】
给你一个n*m的棋盘;
然后你能够无限复制这个棋盘;
在这个棋盘上你有一个起点s;
然后问你,你能不能从这个起点s开始一直走无限远;
【题解】
考虑两个不同棋盘上的点(x1,y1),(x2,y2)(即复制出的另外一个棋盘);
假设他们在第一个棋盘上对应的投影x%n,y%m是相同的;
且它们都能由起点S到达;
即S能到达这两个点;
则可知;
可以从S到达其中的一个点(x1,y1);
然后从那个点再到起点,然后再到另外一个棋盘上的(x2,y2),然后再一直重复上述步骤,再回到(x1,y1)再到(x2,y2)..就能无限延伸了;
必要性是靠直觉的吧;
感觉就是要能一直从一个点然后又回到这个点,才能一直扩展嘛;
做法就是dfs(x,y);
看看vis[x%n][y%m]存的是不是(x,y);
不是的话就输出有解;
(vis[x%n][y%m]和(x,y)就是上面对应的(x1,y1)和(x2,y2) )
否则结束这一层递归;
【Number Of WA】
1
【完整代码】
#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 pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int M = 1500+10;
bool a[M][M],bo[M][M];
pii vis[M][M];
int n,m,x,y;
char s[M];
void out(){
cout <<"Yes"<<endl;
exit(0);
}
void dfs(int x,int y){
int tx = (x%n+n)%n,ty = (y%m+m)%m;
if (!a[tx][ty]) return;
if (bo[tx][ty]){
if (vis[tx][ty].fi !=x || vis[tx][ty].se != y)
out();
return;
}
else
bo[tx][ty] = true,vis[tx][ty] = mp(x,y);
rep1(i,1,4){
int tx = x+dx[i],ty = y+dy[i];
dfs(tx,ty);
}
}
int main(){
//Open();
Close();//scanf,puts,printf not use
//init??????
cin >> n >> m;
rep1(i,0,n-1){
cin >>s;
rep1(j,0,m-1){
if (s[j]=='#')
a[i][j] = 0;
else{
a[i][j] = 1;
if (s[j]=='S'){
x = i,y = j;
}
}
}
}
dfs(x,y);
cout <<"No"<<endl;
return 0;
}
【codeforces 196B】Infinite Maze的更多相关文章
- 【CodeForces 622A】Infinite Sequence
题意 一个序列是, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5....这样排的,求第n个是什么数字. 分析 第n个位置属于1到k,求出k,然后n-i*(i-1)/ ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【POJ 3026】Borg Maze
id=3026">[POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值 ...
- 【23.39%】【codeforces 558C】Amr and Chemistry
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【codeforces 750D】New Year and Fireworks
time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...
- 【29.89%】【codeforces 734D】Anton and Chess
time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【20.51%】【codeforces 610D】Vika and Segments
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【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; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- Multipartfile与File类型相互转换
特殊情况下需要做转换 1.M转F File file = new File(path); FileUtils.copyInputStreamToFile(multipartFile.getInputS ...
- [USACO07OPEN]Catch That Cow
题目:洛谷P1588.HDU2717 题目大意:有一个人在点$n$,一头牛在点$k$,人每秒能从$x$移动到点$x+1$.$x-1$.$2x$,牛不会动,求最少多少秒后人能移动到牛所在的$k$. 思路 ...
- BZOJ 1030 [JSOI2007]文本生成器 (Trie图+DP)
题目大意:给你一堆字符串,一个串不合法的条件是这些字符串中任意一个是这个串的子串,求合法的串的数量 其实这道题比 [HNOI2008]GT考试 那道题好写一些,但道理是一样的 只不过这道题的答案可以转 ...
- freeswitch 中文语音
1.下载中文语音包 链接:https://pan.baidu.com/s/1UODvqj8NAQw7_CRatfl0kg 提取码:qwdn 创建目录 /usr/local/freeswitch/sou ...
- pytorch 7 optimizer 优化器 加速训练
import torch import torch.utils.data as Data import torch.nn.functional as F import matplotlib.pyplo ...
- 阿里云Linux系统安装配置Tomcat方法
本文将tomcat安装到了/alidata/server/目录下,当然也可以安装到其他目录. 1. 下载tomcat:#wget http://apache.fayea.com/tomcat/tomc ...
- url中jsessionid的理解
(1) 这是一个保险措施 因为Session默认是需要Cookie支持的 但有些客户浏览器是关闭Cookie的 这个时候就需要在URL中指定服务器上的session标识,也就是5F4771183629 ...
- HDU 4329 Contest 3
果然换个编译器就过了.总的来说,不难,不过就是处理一些空格.学习了一个新的类 istringstream可以按空格划分.然后,那条式子要理解. 式子的意义是: 找到一个串,该串在query中是第几个找 ...
- NOIP2017提高组模拟赛 7(总结)
NOIP2017提高组模拟赛 7(总结) 第一题 斯诺克 考虑这样一个斯诺克球台,它只有四个袋口,分别在四个角上(如下图所示).我们把所有桌子边界上的整数点作为击球点(除了4个袋口),在每个击球点我们 ...
- 区间不相交&区间覆盖
//code by virtualtan 2018 寒7 区间不相交 #include <cstdio> #include <algorithm> #define MAXN 1 ...