CF1063B Labyrinth】的更多相关文章

可以证明,如果我搜索的话,一个点最多只有两个最优状态:向左剩余步数最大时和向右剩余步数最大时 然后判一判,bfs就好了 dfs会T惨... #include<bits/stdc++.h> #define pa pair<int,int> #define CLR(a,x) memset(a,x,sizeof(a)) using namespace std; typedef long long ll; +; inline ll rd(){ ll x=;; ;c=getchar();}…
大家一起膜Rorshach. 一般的$bfs$会造成有一些点访问不到的情况,在$system\ test$的时候会$WA40$(比如我……). 发现这张地图其实是一个边权只有$0/1$的图,我们需要计算的是从$(r, c)$开始到每一个点的最短路,因为边权只有两种的特性,我们可以用一个双端队列,每一次向上向下走的放在队首,每一次向左向右走放在队尾,就可以得到正确的解. 也可以用优先队列,这样子多一个$log$. 时间复杂度$O(n^2)$. Code: #include <cstdio> #i…
\(Des\) 有一个网格图,上面的格子分为空地和障碍,障碍是不可以走的.现在从给定的起点出发开始到处乱走,最多可以往左走\(l\)次,往右走\(r\)次.求可能到达的点数. \(Sol\) 如果只限制了向左或向右走的次数就要简单一些,所以我们先思考这一种情形. 假设只限制了向左走不能超过\(l\)次.这样转化:对于每个点,它向左走花费的代价是\(1\),其他方向的代价是\(0\).求从给定起点出发,走到每一个点的最小花费.对于某一个点,如果这个花费是\(\leq l\)的,那么这个位置就是可达…
题解 CF1063B [Labyrinth] 完了我发现我做CF的题大部分思路都和别人不一样qwq 这道题其实很水,不至于到紫题 我们只要bfs一下,向四个方向剪下枝,就A了(好像还跑的蛮快?) 是一道锻炼代码能力的好题 Code: #include <bits/stdc++.h> #define check(x, y) (x >= 0 && x < n && y >= 0 && y < m)//判断是否越界 const…
传送门 Description 给你一个\(n~\times~m\)的矩阵,一开始你在第\(r\)行第\(c\)列.你的上下移动不受限制,向左最多移动\(x\)次,向右最多移动\(y\)次.求你最多能到多少个点.包括起始点. Input 第一行是\(n\)和\(m\),代表矩阵规模. 第二行是\(r\)和\(c\),代表你的位置 第三行是\(x\)和\(y\),代表移动限制 下面\(n\)行每行\(m\)个字符,有且仅有'.'和''两种.如果第\(i\)行第\(j\)列是''代表你不能经过这个点…
Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1507    Accepted Submission(s): 520 Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,…
1145. Rope in the Labyrinth Time limit: 0.5 secondMemory limit: 64 MB A labyrinth with rectangular form and size m × n is divided into square cells with sides' length 1 by lines that are parallel with the labyrinth's sides. Each cell of the grid is e…
[POJ1383]Labyrinth 试题描述 The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a little hook on the floor in the center…
Labyrinth Time limit: 1.0 secondMemory limit: 64 MB Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need a program to calculate the surface area of the walls inside the labyrinth. This job…
题目连接 http://poj.org/problem?id=1383 Labyrinth Description The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a litt…
C. The Labyrinth 题目连接: http://www.codeforces.com/contest/616/problem/C Description You are given a rectangular field of n × m cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are…
题目链接 题目: Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 519    Accepted Submission(s): 174 Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每…
Labyrinth Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 4004   Accepted: 1504 Description The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them eithe…
Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1804    Accepted Submission(s): 626 Problem Description 度度熊是一仅仅喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫.该迷宫仅仅能从矩阵左上角第一个方格開始走.仅仅有走到右上角的第一个格子才算走出迷宫,每一次仅仅…
 Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1173    Accepted Submission(s): 388 Problem Description  度度熊是一仅仅喜欢探险的熊.一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上角的第一个格子才算走出迷宫,每…
Labyrinth Problem Description 度度熊是一仅仅喜欢探险的熊.一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上角的第一个格子才算走出迷宫.每一次仅仅能走一格,且仅仅能向上向下向右走曾经没有走过的格子,每个格子中都有一些金币(或正或负.有可能遇到强盗拦路抢劫.度度熊身上金币能够为负,须要给强盗写欠条).度度熊刚開始时身上金币数为0,问度度熊走出迷宫时候身上最多有多少金币? Input 输入的第一行是一个整数T(T < 200).…
题目链接:1063B - Labyrinth/1064D - Labyrinth 题目大意:给定一个\(n\times m\)的图,有若干个点不能走,上下走无限制,向左和向右走的次数分别被限制为\(x\)和\(y\),给出起点并询问有多少个点能够到达. 题解:此题坑多...本弱写裸BFS,WA了一百次_(:з」∠)_ 考虑从点\(A\)到点\(B\)需要向左或者向右走的次数,可以发现若设向左走的次数为\(l\),向右走的次数为\(r\),则\(r-l\)是个定值,因此转换成最短路问题用最短路跑一…
D - Labyrinth 对于位置(i,j), j - c = R - L = const(常数), 其中R表示往右走了几步,L表示往左走了几步 所以R越大, L就越大, R越小, L就越小, 所以只需要最小化L和R中的其中一个就可以了 由于每次变化为0或1,所以用双端队列写bfs, 保证最前面的值最小, 简化版的dijkstra 不过看到好多没写双端队列的也过了...... 代码: #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma…
Labyrinth http://codeforces.com/problemset/problem/1064/D time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output You are playing some computer game. One of its levels puts you in a maze consistin…
D. Theseus and labyrinth 题目连接: http://www.codeforces.com/contest/676/problem/D Description Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1…
D. Labyrinth http://codeforces.com/contest/1064/problem/D 题意: n*m的矩阵,只能往左走l次,往右走r次,上下走无限制,问能走到多少个点. 分析: 01bfs. 直接bfs会出现问题,因为一旦打上标记后,下一次无法访问到,但是下一次的状态还更优. 像这样的样例: ..... .***. ...*. *.**. *.**. *.... 做法:用双端队列,向上走或向下走时就push到队头,向左走或向右走时就push到队尾(其实就是先处理一列…
URAL.1033 Labyrinth (DFS) 题意分析 WA了好几发,其实是个简单地DFS.意外发现这个俄国OJ,然后发现ACRUSH把这个OJ刷穿了. 代码总览 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <sstream> #include <set> #include <map> #…
Rope in the Labyrinth Time Limit:500MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1145 Description A labyrinth with rectangular form and size m × n is divided into square cells with sides' length 1 by lines…
D. Labyrinth 题目链接:https://codeforces.com/contest/1064/problem/D 题意: 给出一个n*m的矩阵以及人物的起点,并且给出x,y,分别代表这个人向左最多走x步,向右最多走y步. 矩阵中存在障碍,问这个人最多能到达多少数量的格子. 题解: 就是一个bfs...只是要稍微剪枝一下,如果发现当前这个点所到达的格子已经被之前的一个点到达过,当且仅当当前点的x或y至少一个比之前到达的点大时,就将这个点入队. 只有这样才能保证解最优. 代码如下: #…
Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 152    Accepted Submission(s): 76 Problem Description 度度熊是一仅仅喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫仅仅能从矩阵左上角第一个方格開始走,仅仅有走到右上角的第一个格子才算走出迷宫,每一次仅仅能走…
Labyrinth POJ - 1383 The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a little hook on the floor in the center of…
E - Labyrinth Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice URAL 1033 Description Administration of the labyrinth has decided to start a new season with new wallpapers. For this purpose they need…
Description The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a little hook on the floor in the center of every fr…
The northern part of the Pyramid contains a very large and complicated labyrinth. The labyrinth is divided into square blocks, each of them either filled by rock, or free. There is also a little hook on the floor in the center of every free block. Th…
先上题目: Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2911    Accepted Submission(s): 1007 Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一…