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 ...
随机推荐
- 利用链式队列(带头节点)解决银行业务队列简单模拟问题(c++)-- 数据结构
题目: 7-1 银行业务队列简单模拟 (30 分) 设某银行有A.B两个业务窗口,且处理业务的速度不一样,其中A窗口处理速度是B窗口的2倍 —— 即当A窗口每处理完2个顾客时,B窗口处理完1个顾客 ...
- PAT-1010 Radix
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...
- 关于运行“基于极限学习机ELM的人脸识别程序”代码犯下的一些错误
代码来源 基于极限学习机ELM的人脸识别程序 感谢文章主的分享 我的环境是 win10 anaconda Command line client (version 1.6.5)(conda 4.3.3 ...
- hexo发文章
http://blog.csdn.net/qq_36099238/article/details/54576089
- 20135323符运锦----第三周:构建一个简单的Linux系统MenuOS
相关知识点 1.arch目录 占据相当庞大的空间,X86目录下代码需要重点关注. 2.init目录 内核启动的相关代码基本都在此目录下,内含MAIN.C,文件中START_KERNEL是整个LINUX ...
- 从零开始学Kotlin-基础语法(1)
从零开始学Kotlin基础篇系列文章 注释 //单行注释 /* 多行注释 */ /** * 多行注释 */ 定义变量/常量 变量定义:var 关键字 var <标识符> : <类型& ...
- App phonegap
云端打包 https://build.phonegap.com/apps phonegap PC端下载 https://www.phonegap.com/getstarted/ 移动端下载 https ...
- html5 & upload files
html5 & upload files https://www.sitepoint.com/html5-ajax-file-upload/ https://www.webcodegeeks. ...
- C# 登录窗口的设计技巧
记得很久之前要用C#做个需要登录的小东西,自己之前完全没有编写WinForm的经验,整个过程中,自己感觉应该怎么写就怎么写,时常导致许多逻辑性的错误,比如在做这个登录窗口的时候,应该实现的效果是,用户 ...
- 【luogu3768】简单的数学题 欧拉函数(欧拉反演)+杜教筛
题目描述 给出 $n$ 和 $p$ ,求 $(\sum\limits_{i=1}^n\sum\limits_{j=1}^nij\gcd(i,j))\mod p$ . $n\le 10^{10}$ . ...