CCF-2015-9-13-04
来源:互联网 发布:mac脚本编辑器 用途 编辑:程序博客网 时间:2024/05/29 09:06
下题为个人做法,只做参考。
二维数组第三个为状态,表示是否已经访问过该条路径。
/*国王给城市修路,两个城市互相有路则为便利城市,路则为便利路,求便利路的条数。第一行输入两个数字m,n ;m 为城市数量,n为路的总数;接下来的n行每行输入两个数i,j : 表示i->j为一条通路最后为一行输出,表示便利路的条数。*/#include "iostream"using namespace std;bool myPorcess(int **p, int start, int end, int size, int deep);int main() {int nCity = 0;int nRoad = 0;cin >> nCity;cin >> nRoad;int **pRoad = new int*[nRoad]();for (int i = 0; i < nRoad; ++i)pRoad[i] = new int[3]();for (int i = 0; i < nRoad; ++i){cin >> pRoad[i][0];cin >> pRoad[i][1];pRoad[i][2] = 0;}int count = 0;for (int i = 0; i < nRoad; ++i) {pRoad[i][2] = 1;if (myPorcess(pRoad, pRoad[i][1], pRoad[i][0], nRoad, 0))count++;for (int j = 0; j < nRoad; ++j)pRoad[j][2] = 0;}cout << count << endl;return 0;}bool myPorcess(int **p,int start,int end,int size,int deep) {if (deep != 0)if (start == end)return true;for (int i = 0; i < size; ++i)if (p[i][0] == start)if (p[i][2] == 1)continue;else {p[i][2] = 1;return myPorcess(p, p[i][1], end, size, 1);}return false;}
0 0
- CCF-2015-9-13-04
- CCF-CSP-2015年9月-题解
- CCF 2015 9-2 日期计算
- CCF-CSP-2015-9-1 数列分段
- CCF-CSP-2015-9-2 日期计算
- CCF 201709-04
- ccf刷题记04
- CCF-2016/9/11
- CCF-2017-9
- ccf
- CCF
- ccf
- 高速公路 ccf 2015年9月第4题
- CCF 2014 9-2 画图
- CCF认证2017-9 除法
- ccf 模板生成系统 2015年9月第3题
- 2015年9月CCF计算机软件能力认证题:模板生成工具
- 2015年9月CCF计算机软件能力认证题:日期计算
- 浏览器解析过程
- 二叉树的创建和遍历
- HDU 5233 杂题
- JSP之POST与GET的区别
- 排序算法 golang 实现
- CCF-2015-9-13-04
- hdu 5444 Elven Postman(模拟)
- C语言strstr()函数常用示例详解[求一个字符串在另一个字符串中出现的次数]
- Android:30分钟弄明白Touch事件分发机制
- 正则表达式
- 查看某个文件的git 历史和更改
- Python类的专用方法
- Invert Binary Tree -- leetcode
- 华为测试 字符加密