Treasure Island(两遍dfs)-- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)
题意:https://codeforc.es/contest/1214/problem/D
给你一个n*m的图,每次可以往右或者往下走,问你使(1,1)不能到(n,m)最少要放多少 ‘ # ’ 。
思路:
最多是2,不能到(n,m)是0,接下来就是判断1。
也就是判断有没有一个点所有路径必须经过。
第一遍dfs往下走优先,第二遍dfs往右走优先,判断两次走法有没有除了起点和终点其他相同的点,如果有就是有截断点。
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>//freopen("C:\\Users\\13606\\Desktop\\草稿.txt","r",stdin);
#include <bitset>
#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
#define ls rt<<1
#define rs rt<<1|1
typedef long long ll;
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int n,m,tot=;
vector<vector<char> >v(N);
map<int,int>mp[N];
map<int,int>mp2[N],vis[N],vis2[N];
struct node
{
int x,y;
};
bool f1,f2;
void dfs1(int x,int y)
{
if(x==n&&y==m)
f1=,vis[x][y]=;
if(f1||vis[x][y]||x>n||y>m)return;
vis[x][y]=;
//pr("%d %d\n",x,y);
if(x+<=n&&v[x+][y]=='.')
dfs1(x+,y);
if(y+<=m&&v[x][y+]=='.')
dfs1(x,y+);
} void dfs2(int x,int y)
{
if(x==n&&y==m)
f2=,vis2[x][y]=;
if(f2||vis2[x][y]||x>n||y>m)return;
vis2[x][y]=;
// pr("%d %d\n",x,y);
if(y+<=m&&v[x][y+]=='.')
dfs2(x,y+);
if(x+<=n&&v[x+][y]=='.')
dfs2(x+,y);
} int main()
{
sc("%d%d",&n,&m);
for(int i=;i<=n;++i)
v[i].push_back('$');
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
char s[];
sc("%1s",s);
v[i].push_back(s[]);
}
}
dfs1(,);
dfs2(,);
bool F=;
for(int i=;i<=n;++i)
{
for(int j=;j<=m;++j)
{
if(i==&&j==||i==n&&j==m)
continue;
if(vis[i][j]&&vis2[i][j])
F=;
}
}
if(vis[n][m]!=)
pr("0\n");
else
{
if(F)
pr("1\n");
else
pr("2\n");
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
Treasure Island(两遍dfs)-- Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises)的更多相关文章
- Educational Codeforces Round 58 (Rated for Div. 2) 题解
Educational Codeforces Round 58 (Rated for Div. 2) 题目总链接:https://codeforces.com/contest/1101 A. Min ...
- Educational Codeforces Round 85 (Rated for Div. 2)
\(Educational\ Codeforces\ Round\ 85\ (Rated\ for\ Div.2)\) \(A. Level Statistics\) 每天都可能会有人玩游戏,同时一部 ...
- Educational Codeforces Round 129 (Rated for Div. 2) A-D
Educational Codeforces Round 129 (Rated for Div. 2) A-D A 题目 https://codeforces.com/contest/1681/pro ...
- Educational Codeforces Round 132 (Rated for Div. 2)
Educational Codeforces Round 132 (Rated for Div. 2) A. Three Doors 简述 题意: 有三扇门(1~3), 其中两扇门后面有对应标号门的钥 ...
- Educational Codeforces Round 35 (Rated for Div. 2)
Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...
- Educational Codeforces Round 63 (Rated for Div. 2) 题解
Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...
- Educational Codeforces Round 59 (Rated for Div. 2) DE题解
Educational Codeforces Round 59 (Rated for Div. 2) D. Compression 题目链接:https://codeforces.com/contes ...
- Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code
Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code 题目链接 题意: 给出\(n\)个俄罗斯套娃,每个套娃都有一个\( ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 64 (Rated for Div. 2)题解
Educational Codeforces Round 64 (Rated for Div. 2)题解 题目链接 A. Inscribed Figures 水题,但是坑了很多人.需要注意以下就是正方 ...
随机推荐
- Maximum GCD(UVA 11827)
Problem:Given the N integers, you have to find the maximum GCD (greatest common divisor) of every po ...
- Linux下更换为阿里yum源
更新日期: 2018-08-06 1.yum源的工作原理 yum是为了解决安装包的依赖关系而生的,如果要源码安装一个软件,需要频繁下载各个包,并解决包的依赖关系.这就好比学门课程,要学会这门课程,就要 ...
- OpenGL 开发环境配置:Visual Studio 2017 + GLFW + GLEW
Step1:Visual Studio 2017 Why 开发环境,后面编译GLFW 和 GLEW也要用 How 这里使用的是Visual Studio 2017的 Community 版本,直接官网 ...
- 【转】HDU 6194 string string string (2017沈阳网赛-后缀数组)
转自:http://blog.csdn.net/aozil_yang/article/details/77929216 题意: 告诉你一个字符串和k , 求这个字符串中有多少不同的子串恰好出现了k 次 ...
- Java线程优先级及守护线程(二)
简述 在操作系统中,线程是可以划分优先级的,优先级较高的线程,得到CPU优先执行的几率就较高一些.设置线程的优先级,有助于帮助线程规划期选择下一个哪一个线程优先执行,但是线程优先级高不代表一定会优先执 ...
- 关于phoenix构建hbase视图,更新hbase表后,视图表是否更新的验证
1:创建表 create 'MY_TABLE', 'CF1','CF2' 2:在hbase上插入一条数据 put ' ,'CF1:V1', 'uwo1' 3:在phoenix上创建视图 create ...
- 单调队列优化dp,k次移动求最长路
洛谷2254 给你k次移动 每次移动给你一个时间段 a,b和方向dir 地图上有障碍物 为了不撞上障碍物你可以施法让箱子停下来 问箱子可以走的最长路 ((以下是洛谷的题解)) /*首先考虑对于时间t来 ...
- FreeMarker学习(内建函数参考)
内容参考:http://freemarker.foofun.cn/dgui_quickstart_basics.html 一.字符串内建函数 boolean: 字符串转为布尔值.字符串必须是 true ...
- ElasticSearch2:集群安装
0.Linux系统参数设置 Linux进程数系统限制查看 [root@ip101 config]# sysctl kernel.pid_max kernel.pid_max = 131072 [roo ...
- Resharper错误提示方法的命名
Resharper-->Options-->C#-->Naming Style