>

题目链接

题意:给定一个有向图,顶点代表水池,入度为零的定点代表水源,等级是1,他们延河道(有向边)冲撞,对于普通的水池来说,题目给定判断它等级的两个准则,问出度为零的那个点的等级是多少。


是一道拓扑排序,每次寻找入度为零的点入队,直到队列为空。

出现的问题:

  1. 当时想的主要思路是对的,但是有一点搞错了,就是对于顶点等级的计算方式,顶点的等级应该是在接受了该顶点所有的入度后再进行计算,否则会出现 1 + 1 + 2 = 3 的 情况。 换句话说就是,考虑的情况不够多,没有考虑到对于一个点,所有的入度方式.

  2. 邻接矩阵的使用问题 , 邻接矩阵一般使用于两点之间只有一条边的情况,在其他情况下使用前,先看明白题意,两点之间是否会出现多条边的情况

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的更多相关文章

  1. UVALive 6467 Strahler Order(拓扑序列)

    In geology, a river system can be represented as a directed graph. Each river segment is an edge; wi ...

  2. UVALive 6467 Strahler Order 拓扑排序

    这题是今天下午BNU SUMMER TRAINING的C题 是队友给的解题思路,用拓扑排序然后就可以了 最后是3A 其中两次RE竟然是因为: scanf("%d",mm); ORZ ...

  3. UVALive 6467

    题目链接 : http://acm.sdibt.edu.cn/vjudge/contest/view.action?cid=2186#problem/C 题意:对于斐波那契数列,每个数都mod m , ...

  4. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  5. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  6. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  7. 【暑假】[实用数据结构]UVAlive 3026 Period

    UVAlive 3026 Period 题目: Period   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

  8. 【暑假】[实用数据结构]UVAlive 4329 Ping pong

    UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: % ...

  9. 【暑假】[深入动态规划]UVAlive 3983 Robotruck

     UVAlive 3983 Robotruck 题目: Robotruck   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format ...

随机推荐

  1. 腾讯 深圳 25928-PHP开发工程师(深圳)

    工作地点:深圳 职位类别:技术类 招聘人数:1人 工作职责: 负责游戏研运体系流程工具及相关产品的开发.维护: 参与支撑系统的需求分析.设计.编码: 承担外包开发成员技术导师,解决技术难点,把控开发质 ...

  2. 20135220谈愈敏Blog5_系统调用(下)

    系统调用(下) 谈愈敏 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.com/course/USTC-1000029000 给Me ...

  3. Spring源码学习:DefaultAopProxyFactory

    /* * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Vers ...

  4. CentOS75 安装Oracle18c

    1. 参考地址 https://blog.csdn.net/u010257584/article/details/50902472https://www.cnblogs.com/kerrycode/a ...

  5. Python的数据结构

    目录 Python内置的数据结构 序列Sequence 映射Mapping 集合Sets Python内置的数据结构 Python语言简洁明了,可以用较少的代码实现同样的功能.这其中Python内置的 ...

  6. pixi.js + three.js

    three.js    最好的webgl 3d渲染库之一, pixi.js    最好的webgl 2d渲染库之一,也许可以把之一去掉 两个库都很精简,如果把两个库结合起来,一定很爽很爽,你说是吧! ...

  7. 统计nginx日志的状态码

    日志格式 61.159.140.123 - - [23/Aug/2014:00:01:42 +0800] "GET /favicon.ico HTTP/1.1" 404 \ &qu ...

  8. nginx提示Job for nginx.service failed because the control的问题

    启动nginx时就报错!Job for nginx.service failed because the control process exited with error code. See &qu ...

  9. 深入理解javascript选择器API系列第三篇——HTML5新增的3种selector方法

    前面的话 尽管DOM作为API已经非常完善了,但是为了实现更多的功能,DOM仍然进行了扩展,其中一个重要的扩展就是对选择器API的扩展.人们对jQuery的称赞,很多是由于jQuery方便的元素选择器 ...

  10. BZOJ2756 SCOI2012奇怪的游戏(二分答案+最大流)

    由数据范围容易想到网络流.由于操作只是对于棋盘上相邻两格,容易想到给其黑白染色. 假设已经知道最后要变成什么数.那么给黑白点之间连边,其流量则表示同时增加的次数,再用源汇给其限流为需要增加的数即可. ...