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) ...
随机推荐
- OpenGL学习进程(11)第八课:颜色绘制的详解
本节是OpenGL学习的第八个课时,下面将详细介绍OpenGL的颜色模式,颜色混合以及抗锯齿. (1)颜色模式: OpenGL支持两种颜色模式:一种是RGBA,一种是颜色索引模式. R ...
- Bootstrap3.0入门学习系列规划[持续更新]
详情请看http://aehyok.com/Blog/Detail/5.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:http ...
- cocos2d-x在Android平台下的音频导致的卡死
先挖个坑,慢慢再来填.出错信息: frameworks/wilhelm/src/android/AudioPlayer_to_android.cpp:779: pthread 0x75f14a00 ...
- Android——BitMap(位图)相关知识总结贴
Android中文API(136) —— Bitmap http://www.apkbus.com/android-54644-1-1.html Android 4.0 r1 API—Bitmap(S ...
- phpredis中文手册——《redis中文手册》 php版
本文是参考<redis中文手册>,将示例代码用php来实现,注意php-redis与redis_cli的区别(主要是返回值类型和参数用法). 目录(使用CTRL+F快速查找命令): Key ...
- AngularJS 模态对话框
本文内容 项目结构 运行结果 index.html mymodal.js 参考资料 本文讲解 Angular JS 实现模式对话框.基于 AngularJS v1.5.3.Bootstrap v3.3 ...
- Windows搭建SVN
1.服务器下载 VisualSVN 地址:http://subversion.apache.org/packages.html 2.然后下载TortoiseSVN客户端,如果要下中文语言包 也在这个页 ...
- 恶心的hadoop集群
具体配置:网上一堆,我说一下我的问题好了! “完全” 分布式集群 注意地方有三点: 1.你的"master" dfs目录中的某个Id不一致,具体位置,有空我再找找.(经过我找了一下 ...
- web端视频直播网站的弊端和优势
在YY上市前后,国内涌出一批类YY视频直播或9158的秀场类网站. 比如六间房,酷六等等 这种web端视频服务基本依靠web本身的特性,用flash直播,靠CDN提供服务. 但是这样的架构有2个问题 ...
- 写essay和research paper必用的17个网站
1.http://scholar.google.com/ 虽然还是Beta版,但个人已觉得现在已经是很好很强大了,Google学术搜索滤掉了普通搜索结果中大量的垃圾信息,排列出文章的不同版本以及被其它 ...