【Codeforces Round #301 (Div. 2) C】 Ice Cave
【链接】 我是链接,点我呀:)
【题意】
给你一个n*m的地图。
每个地图为0的时候可以安全走过,且走过后变成1.
(一定要离开之后才会变成1)
而为1的则走过之后会掉入下一层。
你一开始在初始位置(x1,y1);
且你想到达位置(x2,y2);
且要求到达(x2,y2)并且掉进下一层。
保证(x1,y1)的状态为1.
问你可行与否
【题解】
首先如果x1,y1和x2,y2重合。
那么判断一下周围有没有可以走的0状态就好->走过去再走回来
如果没有就无解
如果不重合。
那么首先判断一下(x1,y1)能否到达(x2,y2);
如果不可以则无解。
如果可以
如果x2,y2状态为1,则有解
否则
看一下(x2,y2)周围是否有两个以上的状态为0的点。(要走到(x2,y2)然后出去再回来)
或者只有一个状态为0的点,且(x2,y2)和(x1,y1)相邻 则有解。
否则无解。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 500;
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
int n,m,r1,c1,r2,c2;
char s[N+10][N+10];
bool can[N+10][N+10];
bool bo[N+10][N+10];
int cnt(int x,int y){
int num = 0;
for (int i = 0;i < 4;i++){
int tx = x + dx[i],ty = y + dy[i];
if (tx<1 || tx > n) continue;
if (ty<1 || ty > m) continue;
num += can[tx][ty];
}
return num;
}
void youjie(){
puts("YES");
exit(0);
}
void wujie(){
puts("NO");
exit(0);
}
bool dfs(int x,int y){
if (x==r2 && y == c2) return true;
if (bo[x][y] || (!can[x][y] && !(x==r1 && y==c1))) return false;
bo[x][y] = true;
bool f = false;
for (int i = 0;i < 4;i++){
int tx = x + dx[i],ty = y + dy[i];
f = f|dfs(tx,ty);
}
return f;
}
int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "rt", stdin);
#endif
scanf("%d%d",&n,&m);
for (int i = 1;i <= n;i++) scanf("%s",s[i]+1);
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
if (s[i][j]=='X')
can[i][j] = 0;
else
can[i][j] = 1;
scanf("%d%d",&r1,&c1);
scanf("%d%d",&r2,&c2);
if (r1 == r2 && c1 == c2){
if (cnt(r1,c1)>0) youjie();
wujie();
}
if (!dfs(r1,c1))
wujie();
else{
if (!can[r2][c2]) youjie();
int cur = cnt(r2,c2);
if (cur > 1) youjie();
if (cur == 1 && (abs(r1-r2)+abs(c1-c2))==1) youjie();
wujie();
}
return 0;
}
【Codeforces Round #301 (Div. 2) C】 Ice Cave的更多相关文章
- 【Codeforces Round #301 (Div. 2) E】Infinite Inversions
[链接] 我是链接,点我呀:) [题意] 给你一个无限长的序列1,2,3,4... 然后给你n个操作. 每个操作ai,bi; 表示调换位置为ai和位置为bi的数的位置. (ai,bi<=10^9 ...
- 【Codeforces Round #301 (Div. 2) D】 Bad Luck Island
[链接] 我是链接,点我呀:) [题意] 剪刀.石头.布各有r,s,p个生活在同一个村子里. 它们两两之间相遇的几率都相同(相遇后就会按照划拳的规则判断输赢,输的人就死掉了). 问你最后只剩下剪刀,只 ...
- 【Codeforces Round #301 (Div. 2) B】 School Marks
[链接] 我是链接,点我呀:) [题意] 已知k门成绩. 总共有n门成绩. 让你构造剩下的n-k门成绩,使得这n门成绩的中位数>=y,并且这n门成绩的和要小于等于x. n为奇数 [题解] 首先判 ...
- 【Codeforces Round #301 (Div. 2) A】 Combination Lock
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟水题 [代码] #include <bits/stdc++.h> using namespace std; cons ...
- 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers
[链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...
- 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes
[题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...
- 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees
[题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...
- 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory
[题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...
- 【Codeforces Round #423 (Div. 2) C】String Reconstruction
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...
随机推荐
- [Python] Format Strings in Python
Single quotes and double quotes can both be used to declare strings in Python. You can even use trip ...
- OpenCascade Sweep Algorithm
OpenCascade Sweep Algorithm eryar@163.com Abstract. Sweeps are the objects you obtain by sweeping a ...
- 游戏开发之UDK引擎介绍和模型导入
2014-09-18 10:01:3 3.7.5" style="border:0px; vertical-align:middle; max-width:100%"&g ...
- ubuntu14.04-安装flash
最近打开搜狐等在线视频,都提示我说flash没有安装,然后就点击安装.进入安装界面 如下所示 然后我们选择版本.之前我一直都是选择版本APT,因为里面标注的是适用于ubuntu10.04+,这时候它会 ...
- 浅析.Net数据操作机制
举个栗子,获取新闻详情的案例. public ActionResult NewsView(int newsId) { var news = _newsService.GetNewsById(newsI ...
- android图像处理系列之三-- 图片色调饱和度、色相、亮度处理
原图: 处理后: 下面贴代码: 一.图片处理层: package com.jacp.tone.view; import java.util.ArrayList; import android.cont ...
- Impala性能优化
不多说,直接上干货! • 执行计划 – 查询sql执行之前,先对该sql做一个分析,列出需要完成这一项查询的详细方案 – 命令:explain sql.profile 要点: • 1.SQL优化,使用 ...
- 玩转redux--从会用到庖丁解牛
目录 为何而写 redux是什么 redux的设计哲学 redux的工作流 redux的几个核心要素 store action reducer actionCreator combineReducer ...
- Android中级第九讲--相机调焦
博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 相机调焦:原理,使用竖直seekbar,根据用户拖拉来获得距离 ...
- 洛谷——P2590 [ZJOI2008]树的统计
https://www.luogu.org/problem/show?pid=2590#sub 题目描述 一棵树上有n个节点,编号分别为1到n,每个节点都有一个权值w. 我们将以下面的形式来要求你对这 ...