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) ...
随机推荐
- Hibernate入门5持久化对象关系和批量处理技术
Hibernate入门5持久化对象关系和批量处理技术 20131128 代码下载 链接: http://pan.baidu.com/s/1Ccuup 密码: vqlv 前言: 前面学习了Hiberna ...
- [推荐]移动H5前端性能优化指南
[推荐]移动H5前端性能优化指南 http://isux.tencent.com/h5-performance.html
- 取消 virtualStore 注册表[启用和禁止 UAC虚拟化]
近日发现,在win2008R2 x64下运行的服务器程序,其注册表读取路径为: [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\SZDomain\itvc1] 但是经 ...
- java代码实现如何获取当前经纬度?(安卓的话可以用GPS取)
import android.app.Activity; import android.os.Bundle; import android.location.*; import android.con ...
- Scala 具体的并行集合库【翻译】
原文地址 本文内容 并行数组(Parallel Array) 并行向量(Parallel Vector) 并行范围(Parallel Range) 并行哈希表(Parallel Hash Tables ...
- Spark核心—RDD初探
本文目的 最近在使用Spark进行数据清理的相关工作,初次使用Spark时,遇到了一些挑(da)战(ken).感觉需要记录点什么,才对得起自己.下面的内容主要是关于Spark核心-RDD的相关 ...
- 百度Web富文本编辑器ueditor在ASP.NET MVC3项目中的使用说明
====================================================================== [百度Web富文本编辑器ueditor在ASP.NET M ...
- Linux实现ftp账号同时访问两个目录方法
在做项目时,客户需要FTP同时访问两个目录,要清楚,在建FTP时,都是一个用户对应一个目录,当FTP用户登录后,就只访问当前目录,如果需要访问到其他目录,得另想办法.刚开始以为使用链接可以实现这个功能 ...
- 更新iOS Distribution Certificates
1. 鑰匙圈存取 -> 憑證輔助程式 -> 從憑證授權要求憑證 email:xxx@xxxx 得到 Blia_20140129.certSigningReques 2.進入開發帳號 憑證 ...
- iOS 基础复习
silverlight知识点:linqToSQL.视图.存储过程.索引.触发器 数据结构:数组.栈.队列.链表.属.图. 排序算法:插入.选择.交换(冒泡).归并 网络开发:HTTP短连接.socke ...