codeforces B. Strongly Connected City(dfs水过)
题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向,
问是否每一个节点都可以由其他的节点到达....
思路:规律没有想到,直接爆搜!每一个节点dfs一次,记录每个节节点被访问的次数!如果每个节点最终的访问次数
和所有节点的数目相同,则输出“YES", 否则输出”NO“
#include <queue>
#include <string>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; char s1[], s2[];
int vis[][];
int cnt[][];
int n, m; void dfs(int x, int y){
if(x< || x>n || y< || y>m || vis[x][y]) return;
++cnt[x][y];
vis[x][y] = ;
if(s1[x] == '<')
dfs(x, y-);
else dfs(x, y+); if(s2[y] == 'v')
dfs(x+, y);
else dfs(x-, y);
} int main(void)
{
scanf("%d%d", &n, &m);
scanf("%s%s", s1+, s2+); for(int i=; i<=n; ++i)
for(int j=; j<=m; ++j){
memset(vis, , sizeof(vis));
dfs(i, j);
}
int s = n*m;
for(int i =; i<=n; ++i)
for(int j=; j<=m; ++j)
if(cnt[i][j] != s){
cout<<"NO"<<endl;
return ;
}
cout<<"YES"<<endl;
return ;
}
codeforces B. Strongly Connected City(dfs水过)的更多相关文章
- cf475B Strongly Connected City
B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...
- Codeforces 475 B Strongly Connected City【DFS】
题意:给出n行m列的十字路口,<代表从东向西,>从西向东,v从北向南,^从南向北,问在任意一个十字路口是否都能走到其他任意的十字路口 四个方向搜,搜完之后,判断每个点能够访问的点的数目是否 ...
- [CF475E]Strongly Connected City 2
题目大意:给一张$n(n\leqslant2000)$个点的无向图,给所有边定向,使定向之后存在最多的有序点对$(a,b)$满足从$a$能到$b$ 题解:先把边双缩点,因为这里面的点一定两两可达. 根 ...
- Codeforces-475B Strongly Connected City
仅仅用推断最外层是不是回路 假设是 则每两个点之间连通 #include<iostream> #include<algorithm> #include<cstdio ...
- @codeforces - 913F@ Strongly Connected Tournament
目录 @description@ @solution@ @accepted code@ @details@ @description@ n 个选手参加了一场竞赛,这场竞赛的规则如下: 1.一开始,所有 ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- algorithm@ Strongly Connected Component
Strongly Connected Components A directed graph is strongly connected if there is a path between all ...
- Strongly connected(hdu4635(强连通分量))
/* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...
- HDU 4635 Strongly connected (Tarjan+一点数学分析)
Strongly connected Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) ...
随机推荐
- windows xp/7命令提示符强制结束指定进程
开始----“运行 ”输入cmd ,然后在命令提示符下输入tasklist,出现如下列表: Image Name PID Session Name ...
- LICEcap – 灵活好用,GIF 屏幕录制工具
LICEcap – 灵活好用,GIF 屏幕录制工具 http://www.appinn.com/licecap/
- Oracle 12c 安装手册
Oracle 12C 首次安装 期待已久的Oracle 12C 终于发布了,我迫不及待的下载了介质,一睹风采. 下载地址:http://www.oracle.com/technetwork/datab ...
- linux centos java 应用服务器配置
备忘: https://oneinstack.com/ 1.用root装jdk nginx.tomcat. 2.配置tomcat主机,上传应用.修改数据库连接帐号,修改log4j文件路径.3.安装my ...
- 传统认知PK网络认知 刚子扯谈烤串认知
文/刚子 2013.7.23 提到认知,有太多的介绍,我就不在秀理论文字了,那样等于自我抄袭式的传播给大家,对于大家也没意思,可以推荐大家到百度里面搜索下”认知结构”,介绍的比我详细.同行老陈说的! ...
- 分布式代码管理 tortoisehg mercurial
下载客户端: https://bitbucket.org/tortoisehg/files/downloads mercurial客户端下载:http://mercurial.s ...
- c++ bind1st 和 bind2nd的用法
std::bind1st 和 std::bind2nd将二元函数转换为一元函数,具体用法参加下面的代码. 代码介绍了两种使用方式,第一种是使用std::less和std::greater,第二种是使用 ...
- phpStorm无法使用svn1.8的解决办法
1.安装SVN的Command Lines Tools. 2.在phpStorm的SVN属性中,将Use Command Line Client填入:C:\Program Files\Tortoise ...
- java代写
Computer Science, Claremont McKenna CollegeCS51.2 - Introduction to Computer Science, Fall 2014Probl ...
- 使用golang 开发的 andriod应用
最近在捣鼓一个东东,就是使用golang开发andriod应用.说起来简单操作起来还挺麻烦,中间又学习了很多东西.比如ubuntu,docker,angular,ionic,jquery mobile ...