CF 某套题 O :Grid (简单BFS)


题意:
从左上角跳到右下角最少需要多少步,跳的规则为:可以向四个方向的任意一个方向跳当前格子中的步数,若跳不到右下角输出IMPOSSIBLE。
题解:
BFS搜索,注意判断边界,标记。
代码:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <cstdlib>
#include <utility>
using namespace std;
#define is_lower(c) (c>='a' && c<='z')
#define is_upper(c) (c>='A' && c<='Z')
#define is_alpha(c) (is_lower(c) || is_upper(c))
#define is_digit(c) (c>='0' && c<='9')
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define IO ios::sync_with_stdio(0);\
cin.tie();\
cout.tie();
#define For(i,a,b) for(int i = a; i <= b; i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,int > pll;
typedef vector<int> vi;
const ll inf=0x3f3f3f3f;
;
const ll inf_ll=(ll)1e18;
const ll maxn=100005LL;
const ll mod=1000000007LL;
+;
pair <int,int> p;
queue <pii> q;
int mp[N][N];
int xx[N][N];
bool vis[N][N];
int main() {
int m,n;
cin >> m >> n;
For(i,,m)
For(j,,n)
scanf("%1d",&mp[i][j]);
p.first = ;p.second = ;
q.push(p);
vis[][] = ;
;
while(!q.empty()){
pii x = q.front();
q.pop();
int step = mp[x.first][x.second];
pii x1;
&&(x.first+step)<=m&&!vis[x.first+step][x.second]){
x1.first = x.first+step,x1.second = x.second;
q.push(x1);
xx[x1.first][x1.second] = xx[x.first][x.second]+;
vis[x1.first][x1.second] = ;
}//向下
&&(x.first-step)<=m&&!vis[x.first-step][x.second]){
x1.first = x.first-step,x1.second = x.second;
q.push(x1);
xx[x1.first][x1.second] = xx[x.first][x.second]+;
vis[x1.first][x1.second] = ;
}// up
&&(x.second+step)<=n&&!vis[x.first][x.second+step]){
x1.first = x.first,x1.second = x.second+step;
q.push(x1);
xx[x1.first][x1.second] = xx[x.first][x.second]+;
vis[x1.first][x1.second] = ;
}
&&(x.second-step)<=n&&!vis[x.first][x.second-step]){
x1.first = x.first,x1.second = x.second-step;
q.push(x1);
xx[x1.first][x1.second] = xx[x.first][x.second]+;
vis[x1.first][x1.second] = ;
}
)
break;
}
)
cout << xx[m][n] <<endl;
else
cout <<"IMPOSSIBLE" << endl;
;
}
CF 某套题 O :Grid (简单BFS)的更多相关文章
- 第46套题【STL】【贪心】【递推】【BFS 图】
已经有四套题没有写博客了.今天改的比较快,就有时间写.今天这套题是用的图片的形式,传上来不好看,就自己描述吧. 第一题:单词分类 题目大意:有n个单词(n<=10000),如果两个单词中每个字母 ...
- Educational Codeforces Round 15 套题
这套题最后一题不会,然后先放一下,最后一题应该是大数据结构题 A:求连续最长严格递增的的串,O(n)简单dp #include <cstdio> #include <cstdlib& ...
- 【POJ 3669 Meteor Shower】简单BFS
流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...
- hdu1312 Red and Black 简单BFS
简单BFS模版题 不多说了..... 直接晒代码哦.... #include<cstdlib> #include<iostream> #include<cstdio> ...
- 【套题】qbxt国庆刷题班D1
Day1 事实上D1的题目还是比较简单的= =然而D1T2爆炸了就十分尴尬--错失一波键盘 看题 T1 传送门 Description 现在你手里有一个计算器,上面显示了一个数\(S\),这个计算器十 ...
- LightOJ 1012 简单bfs,水
1.LightOJ 1012 Guilty Prince 简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- POJ3185(简单BFS,主要做测试使用)
没事做水了一道POJ的简单BFS的题目 这道题的数据范围是20,所以状态总数就是(1<<20) 第一次提交使用STL的queue,并且是在队首判断是否达到终点,达到终点就退出,超时:(其实 ...
- Moscow Pre-Finals Workshop 2016. Japanese School OI Team Selection. 套题详细解题报告
写在前面 谨以此篇题解致敬出题人! 真的期盼国内也能多出现一些这样质量的比赛啊.9道题中,没有一道凑数的题目,更没有码农题,任何一题拿出来都是为数不多的好题.可以说是这一年打过的题目质量最棒的五场比赛 ...
随机推荐
- 获取文件名称 basename 用法
<?phpheader('Content-type:text/html;charset=utf8'); $str = '2390230.png';$str_arr = explode('.',$ ...
- .net 跨域 问题解决
参考地址:http://www.cnblogs.com/moretry/p/4154479.html 在项目上面使用 Nuget 搜索 microsoft.aspnet.webapi.cors 直接下 ...
- poi-对于word的操作(二)
poi对于word文本的底纹和下划线的样式的展现 package poi.test; import java.io.FileOutputStream; import java.math.BigInte ...
- Small Multiple
题目描述 Find the smallest possible sum of the digits in the decimal notation of a positive multiple of ...
- 【GDKOI2016Day1T1-魔卡少女】【拆位】线段树维护区间内所有连续子区间的异或和
题意:给出N个数,M个操作.操作有修改和询问两种,每次修改将一个数改成另一个数,每次询问一个区间的所有连续子区间的异或和.n,m<=100000,ai<=1000 题解: 当年(其实也就是 ...
- 【BZOJ】2705: [SDOI2012]Longge的问题
[题意]给定n,求∑gcd(i,n),(1<=i<=n),n<=2^32 [算法]数论(欧拉函数,gcd) [题解]批量求gcd的题目常常可以反过来枚举gcd的值. 记f(g)为gc ...
- 【BZOJ】1588: [HNOI2002]营业额统计
[算法]平衡树(treap)||双向链表 [题解]treap知识见数据结构. #include<cstdio> #include<algorithm> #include< ...
- NightMare2(SCU4527+dijkstra+二分)
题目链接:http://acm.scu.edu.cn/soj/problem.action?id=4527 题目: 题意:最短路的每条边除了边权之外还会有一个限制(财富,身上带的财富大于这个值则不能通 ...
- webpack自动生成项目的html
1 自动生成多个html页面 设置webpack.config.js中的plugins属性,多次调用plugin插件(new htmlWebpackPlugin()),同时设置对应数量的.js入口文件 ...
- bootstrap-table组合表头
1.效果图 2.html代码 <table id="table"></table> 3.javascript代码 $("#table") ...