(拓扑)确定比赛名次 -- hdu -- 1285
http://acm.hdu.edu.cn/showproblem.php?pid=1285
确定比赛名次
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18484 Accepted Submission(s): 7399
其他说明:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排名。
学了一点后自己写的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm> using namespace std; #define N 1100 #define met(a,b) (memset(a,b,sizeof(a)))
typedef long long LL; struct nnode
{
int u, v;
}a[N]; struct node
{
int num;
bool friend operator < (node n1, node n2)
{
return n1.num > n2.num;
}
}; vector<int>G[N];
int r[N], b[N], k, n; ///r[i] 第i个点的入度 void Slove()
{
int i;
node p, q; priority_queue<node>Q; for(i=; i<=n; i++)
{
if(r[i]==)
{
p.num = i;
Q.push(p);
}
} while(Q.size())
{
p = Q.top(), Q.pop();
b[k++] = p.num; int len = G[p.num].size();
for(i=; i<len; i++)
{
int v = G[p.num][i];
r[v]--;
if(!r[v])
{
q.num = v;
Q.push(q);
}
}
}
} int main()
{
int m; while(scanf("%d%d", &n, &m)!=EOF)
{
int i; met(a, );
met(r, );
met(b, );
for(i=; i<=n; i++)
G[i].clear(); for(i=; i<=m; i++)
{
scanf("%d%d", &a[i].u, &a[i].v);
r[a[i].v]++;
G[a[i].u].push_back(a[i].v);
} k=;
Slove(); for(i=; i<k; i++)
printf("%d%c", b[i], i==k-?'\n':' '); }
return ;
} /** 4 3
1 2
2 3
4 3
4 3
4 3
3 2
2 1 */
之前看别人的代码
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm> using namespace std; #define N 550 int v[N][N], s[N]; void Put(int n)
{
int i, j, k; for(i=; i<=n; i++)
for(j=; j<=n; j++)
{
if(s[j]==)
{
s[j]--;
if(i==n) printf("%d\n", j);
else printf("%d ", j); for(k=; k<=n; k++)
{
if(v[j][k])
{
s[k]--;
}
}
break;
}
}
} int main()
{
int n, m; while(scanf("%d%d", &n, &m)!=EOF)
{
int i, a, b; memset(v, , sizeof(v));
memset(s, , sizeof(s));
for(i=; i<=m; i++)
{
scanf("%d%d", &a, &b);
if(!v[a][b])
{
v[a][b] = ;
s[b]++;
}
} Put(n);
}
return ;
}
(拓扑)确定比赛名次 -- hdu -- 1285的更多相关文章
- 确定比赛名次 HDU - 1285 (拓扑排序)
注意点: 输入数据中可能有重复,需要进行处理! #include <stdio.h> #include <iostream> #include <cstring> ...
- Day4 - G - 确定比赛名次 HDU - 1285
有N个比赛队(1<=N<=500),编号依次为1,2,3,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道 ...
- ACM: HDU 1285 确定比赛名次 - 拓扑排序
HDU 1285 确定比赛名次 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u De ...
- HDU.1285 确定比赛名次 (拓扑排序 TopSort)
HDU.1285 确定比赛名次 (拓扑排序 TopSort) 题意分析 裸的拓扑排序 详解请移步 算法学习 拓扑排序(TopSort) 只不过这道的额外要求是,输出字典序最小的那组解.那么解决方案就是 ...
- 正向与反向拓扑排序的区别(hdu 1285 确定比赛名次和hdu 4857 逃生)
确定比赛名次 Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submis ...
- HDU 1285:确定比赛名次(拓扑排序)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- hdu 1285 确定比赛名次 (拓扑)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- [ACM] hdu 1285 确定比赛名次 (拓扑排序)
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Subm ...
- HDU 1285 确定比赛名次(简单拓扑排序)
题目链接: 传送门 确定比赛名次 Time Limit: 1000MS Memory Limit: 65536K Description 有N个比赛队(1 Input 输入有若干组,每组中的第 ...
随机推荐
- Maven 系列 一 :Maven 快速入门及简单使用
开发环境 MyEclipse 2014 JDK 1.8 Maven 3.2.1 1.什么是Maven? Maven是一个项目管理工具,主要用于项目构建,依赖管理,项目信息管理. 2.下载及安装 下载最 ...
- UI和View 三种控制方式
AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...
- phpstorm的安装和使用
1下载phpstorm #下载地址 https://www.jetbrains.com/phpstorm/ 2激活并安装 create associations 表示的是以后编辑选择的文件也默认用id ...
- snort帮助文档
[1] CentOS6.6下基于snort+barnyard2+base的入侵检测系统的搭建 2 基于Snort的C_S模式的IDS的设计与应用_王会霞.caj [3] Snort 笔记1 - 3种模 ...
- Oracle数据库mybatis 插入空值时报错(with JdbcType OTHER)
参考文档: 1.https://blog.csdn.net/fishernemo/article/details/27649233 2.http://helgaxu.iteye.com/blog/21 ...
- 使用limma、Glimma和edgeR,RNA-seq数据分析易如反掌
使用limma.Glimma和edgeR,RNA-seq数据分析易如反掌 Charity Law1, Monther Alhamdoosh2, Shian Su3, Xueyi Dong3, Luyi ...
- Spring ApplicationContext(五)invokeBeanFactoryPostProcessors
Spring ApplicationContext(六)BeanPostProcessor 产生回顾一下 ApplicationContext 初始化的几个步骤:第一步是刷新环境变量:第二步是刷新 b ...
- unwind
unwind:可以将一个列表展开为一个行的序列1.列表 unwind[1,2,3]as x return x2.创建唯一列表with[1,2,3,3]as coll unwind coll as x ...
- Two Sum LT1
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- jdbc元数据 以及自己动手写一个curd框架
数据库元数据(MetaData):数据库存储结构定义信息 (库.表.列 定义信息) ParameterMetaData 参数元数据 ---- 获得预编译SQL语句中 ? 信息 getParamet ...