1094. The Largest Generation (25)
来源:互联网 发布:淳萃洗发水 知乎 编辑:程序博客网 时间:2024/05/18 01:14
PAT题目链接
牛客网题目链接
题目大意: 找到节点最多的一层,记录其层数和节点数。
#include <iostream>#include <stdio.h>#include<limits.h>#include<queue>#define MAX 101using namespace std;int graph[MAX][MAX];int maxNum=INT_MIN,level;void cengci(int cur){ queue<int>que; int thisNum=1; int tempThisNum=0,tempLevel=0; que.push(cur); while(!que.empty()) { tempLevel++; for(int j=0;j<thisNum;j++) { int x=que.front(); que.pop(); for(int i=0;i<MAX;i++) { if(graph[x][i]==1) { que.push(i); tempThisNum++; } } } thisNum=tempThisNum; if(maxNum<tempThisNum) { maxNum=tempThisNum; level=tempLevel; } tempThisNum=0; }}int main(){ int numOfNode,numOfChild; scanf("%d%d",&numOfNode,&numOfChild); for(int i=1;i<=numOfChild;i++) { int x,num; scanf("%d%d",&x,&num); for(int j=0;j<num;j++) { int y; scanf("%d",&y); graph[x][y]=1; } }///输入完成 ///层次遍历 if(numOfNode>1) { cengci(1); cout<<maxNum<<" "<<level+1; } else cout<<1<<" "<<1; return 0;}总结:pat上提交两次,第一次有两个案例答案错误。测试后发现没有判断输入节点为1的情况。修改后,通过所有案例。牛客网上没有pat上严格。仅依次就通过。
0 0
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- 1094. The Largest Generation (25)
- jQuery源码解读一
- Unity 单例与实例的区别
- CentOS vim插件——Doxygen注释插件(用命令生成各种注释)
- FOJ Problem 2214 Knapsack problem
- 霍夫曼编码和解码
- 1094. The Largest Generation (25)
- xpath对XML进行模糊查询
- StringUtils中 isNotEmpty 和isNotBlank的区别
- 警告:receiver Exported receiver does not require permission
- 利用power_profile.xml获取Android运行时的能耗
- 屏幕尺寸/机型/系统版本判定
- Navicat Premium 无法新建查询问题
- MFC处理bmp图像—Otsu阈值分割
- 安卓使用http下载文件