>

题目链接

题意:给定一个有向图,顶点代表水池,入度为零的定点代表水源,等级是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. yocto-sumo源码解析(二): oe-buildenv-internal

    1 首先,脚本先对运行方式进行了检测: if ! $(return >/dev/null 2>&1) ; then echo 'oe-buildenv-internal: erro ...

  2. 通过sqli-labs学习sql注入——基础挑战之less1

    环境准备: Phpstudy  (PHP+Apache+Mysql) Sql-lab 首先了解下基础知识: URL编码: 因为在浏览器中,当我们访问一个网址的时候,浏览器会自动将用户输入的网址进行UR ...

  3. 转载:ArcEngine 唯一值查询

    转载 http://virgoooos.iteye.com/blog/512329 转载:http://blog.csdn.net/mydriverc/archive/2007/07/26/17092 ...

  4. PAT甲题题解-1078. Hashing (25)-hash散列

    二次方探测解决冲突一开始理解错了,难怪一直WA.先寻找key%TSize的index处,如果冲突,那么依此寻找(key+j*j)%TSize的位置,j=1~TSize-1如果都没有空位,则输出'-' ...

  5. 睡眠猴子——beta阶段项目总结

      Questions: 每个成员在beta 阶段的实践和alpha 阶段有何改进? 团队在beta 阶段吸取了那些alpha 阶段的经验教训? 12 条敏捷开发的原则中, 团队做得最好和最不好的各列 ...

  6. Game over 作业

    终于有一篇不拼代码拼码字的作业了,哈哈哈..... 从寒假到这次结束,经历的博客及编码作业的过程 前面七次作业做个分类: 通往博客园和C++的第一步. 知识点:让我们对C++做一个预习,在学C++前有 ...

  7. ubuntu 12.04下 eclipse的安装

    1首先下载有关的JDK sudo apt-get install openjdk-7-jre 由于是源内的东西,所以只许执行上面这一步,就自动帮你下载 安装 以及配置,无需繁琐的操作. 这里ubunt ...

  8. JS animate动画

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  9. Delphi中Form的position属性与代码自定义窗体位置

    通过Form的Position属性可设置窗体的初始位置,如选择DesktopCenter为桌面中心,ScreenCenter为屏幕中心,等等. 这个属性在很多时候简化了程序代码. 但是,如果设置了po ...

  10. 【设计模式】—— 组合模式Composite

    前言:[模式总览]——————————by xingoo 模式意图 使对象组合成树形的结构.使用户对单个对象和组合对象的使用具有一致性. 应用场景 1 表示对象的 部分-整体 层次结构 2 忽略组合对 ...