UVALive 6467 Strahler Order
>
题目链接
题意:给定一个有向图,顶点代表水池,入度为零的定点代表水源,等级是1,他们延河道(有向边)冲撞,对于普通的水池来说,题目给定判断它等级的两个准则,问出度为零的那个点的等级是多少。
是一道拓扑排序,每次寻找入度为零的点入队,直到队列为空。
出现的问题:
当时想的主要思路是对的,但是有一点搞错了,就是对于顶点等级的计算方式,顶点的等级应该是在接受了该顶点所有的入度后再进行计算,否则会出现 1 + 1 + 2 = 3 的 情况。 换句话说就是,考虑的情况不够多,没有考虑到对于一个点,所有的入度方式.
邻接矩阵的使用问题 , 邻接矩阵一般使用于两点之间只有一条边的情况,在其他情况下使用前,先看明白题意,两点之间是否会出现多条边的情况。
code:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
const double e=exp(1);
const int N = 100009;
int con[1009][1009];
int step[1009][1009];
int check[1009];
int ans[1009];
queue<int> qq;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
int i,j,n,t;
int a,b,head,k,m,p;
int spot;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&k,&m,&p);
memset(check,0,sizeof(check));
memset(con,0,sizeof(con));
memset(ans,0,sizeof(ans));
memset(step,0,sizeof(step));
spot = 0;
while(!qq.empty())
qq.pop();
for(i=1; i<=p; i++)
{
scanf("%d%d",&a,&b);
con[a][b] ++;
check[b]++;
}
for(i =1; i<=m; i++)
{
if(check[i] == 0)
{
ans[i] = 1;
qq.push(i);
check[i] = -1;
spot++;
}
}
while(!qq.empty())
{
head = qq.front();
qq.pop();
for(i = 1; i <= m; i++)
{
while(con[head][i])
{
check[i]--;
con[head][i]--;
step[i][0]++;
step[i][step[i][0]] = ans[head];
if(check[i]==0)
{
qq.push(i);
check[i] = -1;
sort(step[i]+1,step[i]+step[i][0]+1,cmp);
if(step[i][1] > step[i][2])
{
ans[i] = step[i][1];
}
else if(step[i][1] == step[i][2])
{
ans[i] = step[i][1]+1;
}
}
}
}
}
for(i=1; i<m; i++)
if(ans[m] < ans[i])
ans[m] = ans[i];
printf("%d %d\n",k,ans[m]);
}
return 0;
}
UVALive 6467 Strahler Order的更多相关文章
- UVALive 6467 Strahler Order(拓扑序列)
In geology, a river system can be represented as a directed graph. Each river segment is an edge; wi ...
- UVALive 6467 Strahler Order 拓扑排序
这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ ...
- UVALive 6467
题目链接 : http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2186#problem/C 题意:对于斐波那契数列,每个数都mod m , ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- 【暑假】[实用数据结构]UVAlive 3135 Argus
UVAlive 3135 Argus Argus Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld & %l ...
- 【暑假】[实用数据结构]UVAlive 3026 Period
UVAlive 3026 Period 题目: Period Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld ...
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...
- 【暑假】[深入动态规划]UVAlive 3983 Robotruck
UVAlive 3983 Robotruck 题目: Robotruck Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format ...
随机推荐
- Hyperledger Fabric网络节点架构
Fabric区块链网络的组成  区块链网络结构图 区块链网络组成 组成区块链网络相关的节点 节点是区块链的通信主体,和区块链网络相关的节点有多种类型:客户端(应用).Peer节点.排序服务(Orde ...
- PAT甲题题解-1117. Eddington Number(25)-(大么个大水题~)
如题,大水题...贴个代码完事,就这么任性~~ #include <iostream> #include <cstdio> #include <algorithm> ...
- Leetcode题库——48.旋转图像
@author: ZZQ @software: PyCharm @file: rotate.py @time: 2018/11/16 15:41 要求:给定一个 n × n 的二维矩阵表示一个图像.将 ...
- github优缺点
以前bitbucket沒有支援git github可以直接在網站上瀏覽push的圖片 github 可以針對code行數直接留言與回覆 github Markdown支援很好 github 的issu ...
- hybrid项目h5页路由回退问题解决
问题描述: 在hybrid项目里现有h5页A.B.C三个页面,均采用vue开发.其中A.B页采用原生头部,C页采用h5头部.A页通过点击a链接进入B页,B页以同样的方式进入C页,再依次点击各业返回按钮 ...
- 【壹拾壹周】final用户调查
组名: 新蜂组长: 武志远组员: 宫成荣 谢孝淼 杨柳 李峤项目名称:java俄罗斯方块NEO 问卷星由宫成荣同学发布: 温馨提示:点击右键,在新标签中打开图片,单击图片即可放大.或者使用按住ctrl ...
- (改进)Python语言实现词频统计
需求: 1.设计一个词频统计的程序. 2.英语文章中包含的英语标点符号不计入统计. 3.将统计结果按照单词的出现频率由大到小进行排序. 设计: 1.基本功能和用法会在程序中进行提示. 2.原理是利用分 ...
- MySQL基础(二):视图、触发器、函数、事务、存储过程
一.视图 视图是一个虚拟表(非真实存在),其本质是[根据SQL语句获取动态的数据集,并为其命名],用户使用时只需使用[名称]即可获取结果集,并可以将其当作表来使用. 视图和上一篇学到的临时表搜索类似. ...
- python进阶-虚拟环境
virtualenv # 安装 pip install virtualenv # 查看版本,确认安装完成 virtualenv --version # 创建虚拟环境 virtualenv my_env ...
- 用send_keys输入文本的方法
我们使用app时,输入文字都是调用软键盘.在自动化测试中当然也可以调用软键盘,但是由于输入法设计上的差异,有时候不能达到很好的效果. 例如,搜狗拼音输入法: 选择4-咖啡,然而多打几次,输入法就把“咖 ...