【题目链接】: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的更多相关文章

  1. 【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)/ ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【POJ 3026】Borg Maze

    id=3026">[POJ 3026]Borg Maze 一个考察队搜索alien 这个考察队能够无限切割 问搜索到全部alien所须要的总步数 即求一个无向图 包括全部的点而且总权值 ...

  4. 【23.39%】【codeforces 558C】Amr and Chemistry

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  5. 【codeforces 750D】New Year and Fireworks

    time limit per test2.5 seconds memory limit per test256 megabytes inputstandard input outputstandard ...

  6. 【29.89%】【codeforces 734D】Anton and Chess

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【20.51%】【codeforces 610D】Vika and Segments

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  9. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

随机推荐

  1. BZOJ 4864 [BJWC2017]神秘物质 (splay)

    题目大意: 让你维护一个序列,支持: 1.合并两个相邻的数为一个新的数 2.在某个位置插入一个数 3.查询一个区间的任意子区间极差的最大值 4.查询一个区间的任意子区间极差的最小值 前两个操作可以用$ ...

  2. MyBatis学习总结(3)——优化MyBatis配置文件中的配置

    一.连接数据库的配置单独放在一个properties文件中 之前,我们是直接将数据库的连接配置信息写在了MyBatis的conf.xml文件中,如下: <?xml version="1 ...

  3. POJ2891 Strange Way to Express Integers (扩展欧几里德)

    本文为博主原创文章,欢迎转载,请注明出处 www.cnblogs.com/yangyaojia 题目大意 求解一组同余方程 x ≡ r1 (mod a1) x ≡ r2 (mod a2) x ≡ r ...

  4. 兴趣爱好-QQ的本地共享

    QQ这个本地共享简直了,不就实现了公网FTP的功能么?好方便啊,有啥文件共享给好友就直接放在本地就可以了,真好用

  5. Nginx +Tomcat 实现动静态分离(转)

    Nginx +Tomcat 实现动静态分离 动静态分离就是Nginx处理客户端的请求的静态页面(html页面)或者图片,Tomcat处理客户端请求的动态页面(jsp页面),因为Nginx处理的静态页面 ...

  6. OS - 线程和进程的差别

    进程是资源分配的基本单位,又是调度执行的基本单位.比如.用户执行自己的程序,系统就创建一个进程.并为它分配资源,包含各种表.内存空间.磁盘空间.I/O设备等. 然后.把该进程放入进程的就绪队列.进程调 ...

  7. int *p,cons int *p,int const *p,int * const p,const int * const p,int const * const p的差别

     加有constkeyword的几种情况的辨析 const修饰的代码 含义(特点) 等价性 int *p = &num; 1.       能够读自己 2.       能够通过*p改自己 ...

  8. linux centos下载地址

    Centos下载地址 http://r.aminglinux.com

  9. kettle工具的设计原则

    不多说,直接上干货! Kettle工具在设计初,就考虑到了一些设计原则.这些原则里借鉴了以前使用过的其他一些ETL工具积累下的经验和教训. 易于开发:作为数据仓库和ETL开发者,你只想把时间用在创建B ...

  10. ApacheFlink简介

    对无界数据集的连续处理 在我们详细介绍Flink之前,让我们从更高的层面上回顾处理数据时可能遇到的数据集的类型以及您可以选择处理的执行模型的类型.这两个想法经常被混淆,清楚地区分它们是有用的. 首先, ...