ACM之纠结篇:Ordering Tasks

Python爬虫实战:西瓜视频m3u8解析与FFmpeg下载合并 网络爬虫与流媒体解析是Python工程实践中的常见需求,其核心在于通过HTTP请求获取数据并解析特定格式。m3u8作为HLS协议索引文件,将视频切分为ts分片,便于流式传输。结合FFmpeg的多线程处理能力,可高效完成分片下载与合并,技术价值在于提升视频处理效率。典型应用场景包括视频下载、离线缓存等。本文以西瓜视频为例,详细讲解如何使用requests库提取m3u8地址,并调用FFmpeg批量下载ts分片合并为mp4,涵盖请求伪装、索引解析及常见问题排查。 阅读详情

Ordering Tasks

Input: standard input

Output: standard output

Time Limit: 1 second

Memory Limit: 32 MB

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed.

Input

The input will consist of several instances of the problem. Each instance begins with a line containing two integers, 1 <= n <= 100 and m. nis the number of tasks (numbered from 1to n) and m is the number of direct precedence relations between tasks. After this, there will be m lines with two integers i and j, representing the fact that task i must be executed before task j. An instance with n = m = 0 will finish the input.

Output

For each instance, print a line with n integers representing the tasks in a possible order of execution.

Sample Input

5 4
1 2
2 3
1 3
1 5
0 0

Sample Output

1 4 2 5 3


一开始被这题坑了很久,不淡定啊不淡定。。。
题目意思很容易就看明白了,可是看这样例输入和输出,就觉得怎么也不对啊,为什么是这个输出啊???
我就在那纠结是不是输出错了。。。
然后就先不做这题了,先去看其他的题目了。等到其他的题目都做的差不多了,又看到了这题。然后,然后,然后我又看了遍题目。
感觉意思还是一样啊,怎么办???
算了,不管了,就按我自己想的去写吧。代码很快就写好了,然后输入了这些数,我的输出竟然是4 1 5 2 3。。。
一下子又不管三七二十一,交上去再说。
结果。。。AC了。。。不敢相信。。。
然后我回来看了一下输出:For each instance, print a line with n integers representing the tasks in a possible order of execution.

。。。又不淡定了,possible,possible,possible,possible,possible。。。a possible order of。。。

懂了~~~噗!

下面是我AC的代码:

#include <set>
#include <cmath>
#include <stack>
#include <queue>
#include <cstdio>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;

int n, t;
int a[110], b[110];
int map[110][110];

void dfs(int z)
{
a[z] = 1;
for (int i = 0; i < n; i++)
{
if(map[z][i] && !a[i]) dfs(i);
}
b[--t] = z;
}

int main()
{
int m;

while (scanf("%d%d", &n, &m) && (n || m))
{
t = n;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(map, 0, sizeof(map));

for (int i = 0; i < m; i++)
{
int x, y;
scanf("%d%d", &x, &y);
map[x - 1][y - 1] = 1;
}

for (int i = 0; i < n; i++)
{
if (!a[i]) dfs(i);
}

for (int i = 0; i < n - 1; i++)
{
printf("%d ", b[i] + 1);
}
printf("%d\n", b[n - 1] + 1);
}

return 0;
}

CNC数控机床数据采集,CNC数据采集 设备联网 车间数字化 cnc数据采集 cnc机床数据采集 免受权采集 设备联网 阅读详情

相关推荐

【WSL2+Ubuntu+Docker Desktop】迁移到D盘

该篇文章包含将WSL2+ubuntu+Docker Desktop从C盘迁移到D盘

哈茶的博客 3931

Ordering Tasks(拓扑排序)

题目 在图论中,由一个有向无环图的顶点组成的序列,当且仅当满足下列条件时,称为该图的一个拓扑排序(英语:Topological sorting)。 (1)每个顶点出现且只出现一次; (2)若A在序列中排在B的前面,则在图中不存在从B到A的路径。 也可以定义为:拓扑排序是对有向无环图的顶点的一种排序,它使得如果存在一条从顶点A到顶点B的路径,那么在排序中B出现在A的后面。 基本思想: 先把入度为0 的节点找到并打印 删掉入度为0的节点,继续循环1的步骤,直至图为null。 简而言之,就是将有确定的

子夜的博客 264

学习记录(十一)--Pattern Recognition投稿记录

上一周特别忽然通知统计建模要答辩,确定是否晋级国赛,一直在准备答辩的事情,所以上一周没有总结周汇报,深刻检讨!!!不过结果是好的,我们组第二名晋级哦。这周主要是跟大家分享一下我投稿PR(Pattern Recognition)的一个时间线,以及投稿后的工作。一、PR从投稿到接收的时间线2025.4.3 Major Revision(ddl4.23) 当时正在弄比赛和另一个着急推进的文章2025.5.30 Minor Revision 这次小修基本上只有一些格式和简单一点点问题。

qq_54949944的博客 1924

Ordering Tasks(拓扑排序+dfs)

Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task isonly possible if other tasks have already been executed.InputThe input will consist...

weixin_34228617的博客 202

AI Agent在智能投研中的实战:多智能体信息整合与策略生成

那么,什么是AI Agent?简单来说,AI Agent是一种能够感知环境、做出决策并采取行动的自主系统。自主性:能够在没有人类直接干预的情况下运行,对自己的行为和内部状态有一定的控制权。反应性:能够感知环境的变化,并及时做出反应。主动性:不仅能够对环境变化做出反应,还能够主动地设定目标并采取行动实现这些目标。社会性:能够与其他Agent(包括人类和人工智能)进行交互、协作和竞争。它们可以全天候不间断地监控和处理海量信息,大大提升信息处理能力;

AI大模型应用之禅 193

Cadence Sigrity PowerSI实战:从.brd到S参数提取的完整避坑指南

本文详细介绍了使用Cadence Sigrity PowerSI进行信号完整性分析的完整流程,从.brd文件预处理到S参数提取的关键技巧。通过实战案例和避坑指南,帮助工程师高效解决高速PCB设计中的信号质量问题,提升仿真精度和设计效率。

carrot的博客 696

拓扑排序:Ordering Tasks

DescriptionJohn has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist

Davenny:~我今天该吃点什么捏~ 456

从平面到立体:一张图看懂MOSFET、FinFET到GAAFET的演变史(附结构对比图)

本文深入解析了半导体晶体管从平面MOSFET到三维FinFET,再到全环绕栅极GAAFET的技术演进历程。通过结构对比图和物理原理分析,揭示了每一次创新如何解决短沟道效应等关键挑战,推动芯片性能提升。特别关注GAAFET作为最新技术突破的架构特点和性能优势。

weixin_30892037的博客 699

拓扑排序简单题

UVA10305 John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist...

night_dust的博客 1123

实战:RK3568 Android14 调试 MIPI DSI 液晶屏

LCD1_RST -> 对应原理图网络连接到 GPIO。LCD1_PWR_EN ->用于给屏幕 VCC 供电。LCD0_BL_EN / LCD0_BL_PWM -> MP3302 升压芯片驱动 LED 灯条。![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/100f2be7f763494da1032464e272e63b.png&pinctrl {/* 配置 LCD_RST 和 LCD_EN */

qq_33427070的博客 1551

海康Visionmaster-全局脚本:VM 加载方案后自动执行 的方法,如何让VM在方案加载后自动执行流程?

海康Visionmaster-全局脚本:VM 加载方案后自动执行 的方法,如何让VM在方案加载后自动执行流程?

视觉人机器视觉的博客 2039

uva 10305 - Ordering Tasks

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several

NiaNiaJR的专栏 855

AI 实战篇 |基于 AI开放平台实现 人脸识别对比 功能,超详细教程【附带源码】

本篇文章来学习一下怎样使用 Unity实现简单地人脸识别 功能。 关于人脸识别,我们可以选择很多平台的SDK接入Unity来实现人脸识别的功能。

努力前行,总会成为自己心中的那道光 5万+

Ordering Tasks (排序任务)

这一题的意思是完成某项工作的前提是先完成另一项工作,给出部分先后顺序,判断出全部工作完成的顺序,可能会有多个答案,输出一个即可。 例如 有5个工作 有4个部分顺序,1在2的前面,2在3的前面,1在3的前面,1在5的前面。 可知1、2、3的先后顺序不变,1、5的先后顺序不变,中间可以插其他的元素, 而4可以放在任意位置。 这一题就是一个拓扑排序,将前面带有限定元素的标记起来,每有...

shiuxin的博客 857

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

UVA 10305- Ordering Tasks(经典拓扑排序)

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several...

Endeavor_G的博客 379

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

UVa 10305 Ordering Tasks(拓扑排序)

原题  Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input wi

快速进入竞赛模式! 604

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

UVaOJ10305---Ordering Tasks

10305 - Ordering Tasks Time limit: 3.000 seconds   John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already

c随遇er安的专栏 583

UVa 10305 - Ordering Tasks【拓扑排序】

Ordering Tasks John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The in

Mr丶Gao 713

【刘汝佳可运行代码】Ordering Tasks UVA - 10305【两种解法】

立志用最少的代码做最高效的表达 John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several instances of the problem. Each instan

weixin_43899069的博客 1907

Ordering Tasks(优先工作)拓补排序

Ordering Tasks工具 queue vector 思路主要是处理好每个点的入度的关系,当一个节点的前驱节点全部被处理的时候,表示该节点能被处理,每处理一个节点,他对应的后序节点的入度都减1#include <iostream> #include <vector> #include <string> #include <queue> #include <memory.h> using nam

Vilin的博客 940

Ordering Tasks 拓扑排序

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several i...

qq_42434171的博客 279

UVA10305 Ordering Tasks【拓扑排序】

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of severa...

海岛Blog 888

Ordering Tasks

John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task is only possible if other tasks have already been executed. Input The input will consist of several i...

沈君乱 281

10305 - Ordering Tasks(****)拓扑排序

/* 简单拓扑排序问题 深度优先,数组st作为存储 */ #include &lt;cstdio&gt; #include &lt;cstring&gt; const int nMax=105; int n,m; int G[nMax][nMax],visit[nMax],st[nMax]; int top; void dfs(int u) { visit[u]=1; for(int v=...

lianxiangbus 165

UVA 10305 - Ordering Tasks

#include int main() { int n, m; while (scanf("%d%d", &n, &m), n) { int edge[105][105] = {0}, indegree[105] = {0}; for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); edge[a

Bingo 1844

C - Ordering Tasks UVA - 10305 【拓扑排序】

#include&lt;iostream&gt; #include&lt;cstring&gt; #define ms(a) memset(a,0,sizeof(a)) using namespace std; const int maxn=1e3+10; int n,m; int a[maxn][maxn]; int in[maxn]; void toposort(){ for...

HPUZJH 306
上一篇: UVA 10557 XYZZY
下一篇: N 封信 with N 信封
ColorWaterer
博客等级 码龄12年 16粉丝 128原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值