题意:有横向和纵向的街道,每个街道只有一个方向,垂直的街道相交会产生一个节点,这样每个节点都有两个方向,
问是否每一个节点都可以由其他的节点到达....
思路:规律没有想到,直接爆搜!每一个节点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水过)的更多相关文章

  1. cf475B Strongly Connected City

    B. Strongly Connected City time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. Codeforces 475 B Strongly Connected City【DFS】

    题意:给出n行m列的十字路口,<代表从东向西,>从西向东,v从北向南,^从南向北,问在任意一个十字路口是否都能走到其他任意的十字路口 四个方向搜,搜完之后,判断每个点能够访问的点的数目是否 ...

  3. [CF475E]Strongly Connected City 2

    题目大意:给一张$n(n\leqslant2000)$个点的无向图,给所有边定向,使定向之后存在最多的有序点对$(a,b)$满足从$a$能到$b$ 题解:先把边双缩点,因为这里面的点一定两两可达. 根 ...

  4. Codeforces-475B Strongly Connected City

    仅仅用推断最外层是不是回路  假设是   则每两个点之间连通 #include<iostream> #include<algorithm> #include<cstdio ...

  5. @codeforces - 913F@ Strongly Connected Tournament

    目录 @description@ @solution@ @accepted code@ @details@ @description@ n 个选手参加了一场竞赛,这场竞赛的规则如下: 1.一开始,所有 ...

  6. 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP

    [题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...

  7. algorithm@ Strongly Connected Component

    Strongly Connected Components A directed graph is strongly connected if there is a path between all ...

  8. Strongly connected(hdu4635(强连通分量))

    /* http://acm.hdu.edu.cn/showproblem.php?pid=4635 Strongly connected Time Limit: 2000/1000 MS (Java/ ...

  9. HDU 4635 Strongly connected (Tarjan+一点数学分析)

    Strongly connected Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) ...

随机推荐

  1. JavaScript 语句 for

    循环for语句: for(var i =1;i<=5;i++)(初始条件:循环条件:状态改变) { 循环体 } 循环的作用:反复执行某段代码 四要素:初始条件.循环条件.循环体.状态改变 例题1 ...

  2. ssh sftp scp命令

    scp local_file remote_username@remote_ip:remote_folder 或者 scp local_file remote_username@remote_ip:r ...

  3. 解决ASP.NET在IE10中Session丢失问题【转】

    今天发现在IE10中登录我公司的一个网站时,点击其它菜单,页面总会自动重新退出到登录页,后检查发现,IE10送出的HTTP头,和.AUTH Cookie都没问题,但使用表单验证机制(FormsAuth ...

  4. angular post表单

    参数文章:http://angularjs.cn/A0qF angularjs中Post使用的是json的交互方法,一般服务器还没达到这个阶段,我们可以用回传统的&参数的方法: var myA ...

  5. Android开发之蓝牙--扫描已经配对的蓝牙设备

    一. 什么是蓝牙(Bluetooth)? 1.1  BuleTooth是目前使用最广泛的无线通信协议 1.2  主要针对短距离设备通讯(10m) 1.3  常用于连接耳机,鼠标和移动通讯设备等. 二. ...

  6. [转载] Redis

    转载:http://snowolf.iteye.com/blog/1630697 大约一年多前,公司同事开始使用Redis,不清楚是配置,还是版本的问题,当时的Redis经常在使用一段时间后,连接爆满 ...

  7. How to import library ?

    Android Studio: Download or git the library. (for example: the library folder named ActionBarSherloc ...

  8. Spring3系列4-多个配置文件的整合

    Spring3系列4-多个配置文件的整合 在大型的Spring3项目中,所有的Bean配置在一个配置文件中不易管理,也不利于团队开发,通常在开发过程中,我们会按照功能模块的不同,或者开发人员的不同,将 ...

  9. c#操作word表格

    http://www.webshu.net/jiaocheng/programme/ASPNET/200804/6499.html <% if request("infoid" ...

  10. java-cef系列视频第二集:搭建开发环境

    上一集我们介绍了如何从官方代码编译java-cef. 本视频介绍了如何使用eclipse搭建java-cef二次开发环境. 下一集我们将给java-cef添加flash支持. 本作品采用知识共享署名- ...