确定比赛名次  

Time Limit(Common/Java):1000MS/3000MS     Memory Limit:65536KByte
Total Submit: 23            Accepted: 19

Description

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

Input

输入有若干组,每组中的第一行为二个数N(1<=N<=500),M(0<=M<=10000);其中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

Uploader

crq

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
const int maxn = 510; int gn, gm;
vector<int> v[maxn];
int cnt[maxn];//记录每个节点的入度. vector<int> out;
vector<int> gres; void Init() {
int i;
gres.clear();
out.clear();
memset(cnt, 0, sizeof(cnt));
for(i = 1; i <= gn; i++) {
v[i].clear();
}
} void Work() {
int i, now, Size;
for(i = 1; i <= gn; i++) {
if(cnt[i]==0) {
out.push_back(i);
}
}
while(!out.empty()) {//应该用优先队列。
sort(out.begin(), out.end());
now = out[0];
gres.push_back(now);
out.erase(out.begin());
Size = v[now].size();
for(i = 0; i < Size; i++) {
cnt[v[now][i]]--;
if(cnt[v[now][i]]==0) out.push_back(v[now][i]);
}
}
Size = gres.size();
if(Size == 1) {
printf("%d\n", gres[0]);
return;
}
for(i = 0; i < Size-1; i++) {
printf("%d ", gres[i]);
}
printf("%d\n", gres[i]);
} int main()
{
int i;
int from, to;
while(scanf("%d%d", &gn, &gm) != EOF) {
Init();
for(i = 1; i <= gm; i++) {
scanf("%d%d", &from, &to);
v[from].push_back(to);
cnt[to]++;
}
for(i = 1; i <= gn; i++) {
sort(v[i].begin(), v[i].end());
}
Work();
}
return 0;
}

TOJ3651确定比赛名次的更多相关文章

  1. hduoj 1285 确定比赛名次

    http://acm.hdu.edu.cn/showproblem.php?pid=1285 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory ...

  2. HDU 1285 确定比赛名次(简单拓扑排序)

    题目链接: 传送门 确定比赛名次 Time Limit: 1000MS     Memory Limit: 65536K Description 有N个比赛队(1 Input 输入有若干组,每组中的第 ...

  3. ACM: HDU 1285 确定比赛名次 - 拓扑排序

     HDU 1285 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u De ...

  4. HDU 1285 确定比赛名次

    传送门 确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. HDU 1285 拓普排序 基本模板例题 确定比赛名次

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  6. (hdu)1285 确定比赛名次

    Problem Description 有N个比赛队(<=N<=),编号依次为1,,,....,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接 ...

  7. hdoj 1285 确定比赛名次【拓扑排序】

    确定比赛名次 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. 确定比赛名次(map+邻接表 邻接表 拓扑结构 队列+邻接表)

    确定比赛名次 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submis ...

  9. B - 确定比赛名次

    B - 确定比赛名次 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit S ...

随机推荐

  1. 【LeetCode】27 - Remove Element

    Given an array and a value, remove all instances of that value in place and return the new length. T ...

  2. 使用cocos2d-x 3.2下载图片资源小例子

    cocos2d-x(ios)下载资源可以使用以下两种方式: 第一种使用libcurl下载图片 使用这种方法需要注意的是,我们需要引入libcurl.a这个库,同时配置对应的库目录和头文件目录具体方法是 ...

  3. OC动态特性

    今天是2.15周日,快要过年了,我以一个实习生的身份在公司工作了快要两个月了吧,什么是北漂,北漂就是感觉生活节奏变了,以前困了可以上课睡觉,累了可以回家休息数周,人际交往乏了,可以躲起来看着窗外的雨或 ...

  4. Objective C静态代码扫描和代码质量管理 OClint + SonarQube

    OClint是针对C, C++及Objective C代码的静态扫描分析工具,而SonarQube是一个开源的代码质量管理平台.本文将实现将OClint的扫描结果导入到SonarQube中,已实现对O ...

  5. enumerate

    enumerate 函数用于遍历序列中的元素并分配一个序号(序号默认从零开始 可以制定任意值): >>> for i,j in enumerate(('a','b','c')): p ...

  6. oracle不用tsname文件的时候着怎么办

    oracle\product\10.2.0\client_2\odp.net\PublisherPolicy\Policy.9.2.Oracle.DataAccess.config 找到newVers ...

  7. Dell商用台式机、笔记本、服务器800电话

    戴尔Optiplex商用台式机 售后服务电话 800-858-0950 选1选2选2 戴尔Latitude商用笔记本 售后服务电话 800-858-0950 选1选3选2 戴尔服务器PowerEdge ...

  8. HDU 5489 Removed Interval (LIS变形)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5489 给你n个数,要删去其中连续的L个,问你删去之后的LIS最大是多少? 我们先预处理出以i下标为开头 ...

  9. CodeForces 709A Juicer (水题, 模拟)

    题意:给定 n 个桔子的大小,一个杯子的容积,一个最大限度,挨着挤桔子汁,如果大小大于限度,扔掉,如果不杯子满了倒掉,问你要倒掉多少杯. 析:直接按要求模拟就好,满了就清空杯子. 代码如下: #pra ...

  10. java提高数据库访问效率代码优化

    package com.jb.jubmis.comm; import java.sql.Connection;import java.sql.ResultSet;import java.sql.SQL ...