>

题目链接

题意:给定一个有向图,顶点代表水池,入度为零的定点代表水源,等级是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. POJ 2431 (优先队列)

    题目链接:https://vjudge.net/problem/POJ-2431 思路: “ 在卡车行驶途中, 只有经过加油站才能加油.” 我们不妨转变思路, 理解成“当卡车驶过加油站时就获得了加油的 ...

  2. git 和 github 链接

    第一步  再电脑上安装git 请自行搜索   到你需要的一个目录下:例如/gittest 首先创建文件,然后  git  add  和 git commit  不然直接查看  git branch - ...

  3. springmvc 集成apache cxf 开发webservice 示例

    今天需要在springmvc中增加webservice功能,试了多次axis2,和cxf都不行,后来发现在springmvc中最好用cxf集成非常方便,在又一次尝试后终于把demo整合到现有的项目中 ...

  4. Linux内核分析第三周总结

    构造一个简单的Linux系统MenuOS 操作系统的"两把宝剑":中断上下文的切换(保存现场和恢复现场).进程上下文的切换 Linux内核源代码简介 --------------- ...

  5. Jquery封装ajax

    Jquery封装ajax   Load方法     <!-- 将jquery.js导入进来 -->     <script type="text/javascript&qu ...

  6. Four-Operations

    开发环境:Eclipse 结对小伙伴:201306114416 陈键 (http://www.cnblogs.com/be-the-one/) 201306114452 吴舒婷 (http://www ...

  7. Node.js & SSR

    Node.js & SSR nest.js https://github.com/nestjs/nest next.js 中文文档 https://nextjs.org/learn/ Grap ...

  8. 免费SSL证书申请 2018年至简教程

    Let’s Encrypt是国外一个公共的免费SSL项目,由 Linux 基金会托管,它的来头不小,由Mozilla.思科.Akamai.IdenTrust和EFF等组织发起,目的就是向网站自动签发和 ...

  9. Tether USDT 节点钱包的安装与使用

      当前,在进行数字资产交易的过程中,由于各国政府的政策因素,法币成为数字资产交易的一个重要问题.在法币接入数字资产交易的过程中,通常是用某种数字资产对法币进行锚定,例如bitshares上面的许多b ...

  10. aop 切点匹配规则