【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; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
随机推荐
- ES6 学习6 数组的扩展
本章学习要点: 扩展运算符 Array.from() Array.of() 数组实例的 copyWithin() 数组实例的 find() 和 findIndex() 数组实例的 fill() 数组实 ...
- Wepy--小程序自定义底部tabBar
PS后续: 说来惭愧, 没想到这篇文章浏览的人有点多. 说实话写的挺乱的. 并且自定义tabbar还有闪屏的问题. 因为有好几位道友都问了这个问题, 其中一位因为项目很急,所以就研究了一下(也是借鉴 ...
- JavaScript学习笔记(第二天)
数组 为什么要学习数组 之前学习的数据类型,只能存储一个值(比如:Number/String.我们想存储班级中所有学生的姓名,此时该如何存储? 数组的概念 所谓数组,就是将多个元素(通常是同一类型)按 ...
- UVALive-7198 Tall orders 微积分 二分
题目链接:https://cn.vjudge.net/problem/UVALive-7198 题意 有悬链线方程$ f(x)=a \cdot cosh(\frac{s}{a}) $, 现有两个电线杆 ...
- 页面下载文件方法,post与get
一般下载文件,常见使用的是window.open('url'):方法进行下载.若需要带参数,直接在url后面拼接参数,进行传递.window.open方法仅可以进行get方法进行参数提交. 若需要进行 ...
- windows下的ubuntu
办公用Windows确实方便,但对于开发和学习还是用Linux比较好. 在Windows下安装Linux子系统 windows10中推出了Linux子系统,这个功能对开发和学习来说真的很好,非常方便. ...
- 调整mysql数据库最大连接数
1.查看mariadb数据库最大连接数,默认为151 MariaDB [(none)]> show variables like 'max_connections'; +------------ ...
- thinkphp 多个字段的不同关系的查询条件实现 .
tp的$map不同条件默认是 and ,如果要用or<><><><>如下 例如查询Stu表中年龄大于18,或者身高低于180cm的男性(1为男性),(例 ...
- codevs 1803 志愿者招募
1803 志愿者招募 2008年NOI全国竞赛 时间限制: 2 s 空间限制: 128000 KB 题目等级 : 大师 Master 题目描述 Description 申奥成功后,布布经过不懈努 ...
- 轻松学习JavaScript十七:JavaScript的BOM学习(二)
JavaScript计时事件 通过使用JavaScript中的BOM对象中的window对象的两个方法就是setTimeout()方法和claerTimeout()方法,我们 有能力作到在一个设定的时 ...