博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1285 确定比赛名次【字典序最小的拓扑排序 + 优先队列】
阅读量:7294 次
发布时间:2019-06-30

本文共 2200 字,大约阅读时间需要 7 分钟。

确定比赛名次

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33964 Accepted Submission(s): 13321

Problem Description

有N个比赛队(1<=N<=500),编号依次为1,2,3,。。。。,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前。现在请你编程序确定排名。

Input

输入有若干组,每组中的第一行为二个数N(1<=N<=500),M;其中N表示队伍的个数,M表示接着有M行的输入数据。接下来的M行数据中,每行也有两个整数P1,P2表示即P1队赢了P2队。

Output

给出一个符合要求的排名。输出时队伍号之间有空格,最后一名后面没有空格。

其他说明:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前;输入数据保证是正确的,即输入数据确保一定能有一个符合要求的排名。

Sample Input

4 3
1 2
2 3
4 3

Sample Output

1 2 4 3

Author

SmallBeer(CML)

Source

杭电ACM集训队训练赛(VII)
【注意】:符合条件的排名可能不是唯一的,此时要求输出时编号小的队伍在前(编号小在前)

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug() puts("++++")#define gcd(a,b) __gcd(a,b)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr(x) ((x)*(x))#define ms(a,b) memset(a,b,sizeof(a))#define sz size()#define be begin()#define pu push_up#define pd push_down#define cl clear()#define lowbit(x) -x&x#define all 1,n,1#define rep(i,n,x) for(int i=(x); i<(n); i++)#define in freopen("in.in","r",stdin)#define out freopen("out.out","w",stdout)using namespace std;typedef long long LL;typedef unsigned long long ULL;typedef pair
P;const int INF = 0x3f3f3f3f;const LL LNF = 1e18;const int maxn = 1e5 + 20;const int maxm = 1e6 + 10;const double PI = acos(-1.0);const double eps = 1e-8;const int dx[] = {-1,1,0,0,1,1,-1,-1};const int dy[] = {0,0,1,-1,1,-1,1,-1};const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int n,m,num,ok,u,v;vector
G[maxn];int ans[maxn];char s[10];int inDeg[maxn],x;int a,c;char b;priority_queue
,greater
> q;void topSort(){ int num=0; while(!q.empty()) q.pop(); for(int i=1;i<=n;i++) if(!inDeg[i]) q.push(i); while(!q.empty()) { int now = q.top(); q.pop(); ans[++num]=now; for(int i=0; i

转载于:https://www.cnblogs.com/Roni-i/p/9180180.html

你可能感兴趣的文章
CentOS 7 开放3306端口访问
查看>>
执行力
查看>>
关于毛刺
查看>>
微信小程序自定义微信客服按钮
查看>>
Ural 1014 Product of Digits NYOJ 270 数的分解 解题报告
查看>>
SPOJ1812 LCS2 - Longest Common Substring II
查看>>
CSS属性(display)
查看>>
具体数学第二版第二章习题(1)
查看>>
第十四章 字符、字符串、编码
查看>>
注意!ASP.NET MVC 3 的一个 OutputCache 问题
查看>>
单行文本垂直居中
查看>>
Remove Element
查看>>
C语言 结构体
查看>>
蓝桥杯-历届试题-公式求值
查看>>
快速排序
查看>>
冒泡排序
查看>>
(七)Action访问Servlet API
查看>>
POJ2960 S-Nim(博弈论:sg函数)
查看>>
$().each()和$.each()
查看>>
iconfont字体图标
查看>>