PAT 甲级 1146  Topological Order

深度学习—各种卷积 深度学习之各种卷积了解知识 阅读详情

1146 Topological Order (25 point(s))

This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options.

gre.jpg

Input Specification:

Each input file contains one test case. For each case, the first line gives two positive integers N (≤ 1,000), the number of vertices in the graph, and M (≤ 10,000), the number of directed edges. Then M lines follow, each gives the start and the end vertices of an edge. The vertices are numbered from 1 to N. After the graph, there is another positive integer K (≤ 100). Then K lines of query follow, each gives a permutation of all the vertices. All the numbers in a line are separated by a space.

Output Specification:

Print in a line all the indices of queries which correspond to "NOT a topological order". The indices start from zero. All the numbers are separated by a space, and there must no extra space at the beginning or the end of the line. It is graranteed that there is at least one answer.

Sample Input:

6 8
1 2
1 3
5 2
5 4
2 3
2 6
3 4
6 4
5
1 5 2 3 6 4
5 1 2 6 3 4
5 1 2 3 6 4
5 2 1 6 3 4
1 2 3 4 5 6

Sample Output:

3 4

经验总结:

不知道为什么,PAT很喜欢从408里面找题目(可能是因为出题人也考过408吧0.0),题目不是很难,在输入边的时候,记录所有顶点的单向邻接点,并且记录所有点的入度。查询时,每输入一个点,就判断其入度是否为0,不为0,则不是拓扑排序,然后将此点指向的所有点的入度减一,查询至结束,输出即可~

AC代码

#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=1010;
int n,m,k,indegree[maxn]={0},tdegree[maxn],a,b;
vector<int> adj[maxn];

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i)
	{
		scanf("%d%d",&a,&b);
		++indegree[b];
		adj[a].push_back(b);
	}
	scanf("%d",&k);
	bool f=false;
	for(int i=0;i<k;++i)
	{
		for(int i=1;i<=n;++i)
			tdegree[i]=indegree[i];
		bool flag=false;
		for(int j=0;j<n;++j)
		{
			scanf("%d",&a);
			if(tdegree[a]!=0)
				flag=true;
			for(int x=0;x<adj[a].size();++x)
				--tdegree[adj[a][x]];
		}
		if(flag==true)
			if(f==false)
			{
				printf("%d",i);
				f=true;
			}
			else
				printf(" %d",i);
	}
	return 0;
}

 

Linux环境下OpenSSH升级到 OpenSSH_9.8p1(内置保姆级教程并包含openssl升级过程) 2024年7月1日接到安全部门同事邮件通知,目前生产环境及测试环境服务器Openssh存在远程代码执行漏洞(CVE-2024-6387),漏洞等级高,且攻击者可以成功利用该漏洞获得远程root shell最高权限从而执行任意代码及命令,主要受影响版本为8.5p1 阅读详情

相关推荐

STM32实现webserver显示数据及配置参数

其实提到的将fsdata.c重命名为fsdata_custom.c,可以不重命令,将/LWIP/Target/lwipopts.h中HTTPD_USE_CUSTOM_FSDATA 定义为0,这样HTTPD_FSDATA_FILE将使用fsdata.c,避免每次生成fsdata.c需要重命令的麻烦。2、登录成功后,板卡根据板卡配置类型,返回对应的数据页面,该页面可实现数据校准、清零,以及进行到板卡参数设置页面。目前还未实现post功能以及http身份验证功能。3、板卡参数设置页面。

2699

1146 Topological Order (PAT甲级)

【代码】1146 Topological Order (PAT甲级)

linh2006的博客 191

SPM12最新安装教程:Matlab2021a用户必看的路径配置技巧

本文为Matlab2021a用户提供SPM12的深度安装与路径配置指南。针对新版Matlab的路径管理变化,详细解析了传统方法失效的原因,并推荐通过创建startup.m文件实现SPM12路径的永久化、自动化配置,确保神经影像分析环境的稳定与高效。

weixin_29061509的博客 317

PAT【甲级】1146

题目链接:PAT【甲级】1146 题目简述:给定一个有向图,问所查询的几组序列中,不是该图的拓扑排序的是哪组。 #include<bits/stdc++.h> using namespace std; unordered_map<int, int> indegree; vector<vector<int>> graph; vector<int> ans; int main(){ int N, M, K; int c, c1, c

qq_41375322的博客 213

手把手教你使用transciver-ip核的配置

手把手教你使用transciver-ip核的配置

u012938458的博客 5430

实战分享:一文读懂RS-232总线

RS-232标准接口(又称EIARS-232)是常用的串行通信接口标准之一,它是由美国电子工业协会(Electronic IndustryAssociation,EIA)联合贝尔系统公司、调制解调器厂家及计算机终端生产厂家于1970年共同制定,其全名是“数据终端设备(DTE)和数据通信设备(DCE)之间串行二进制数据交换接口技术标准”。

阿荣嵌入式 8542

PAT1146 Topological Order(拓扑序列)

PAT1146原题题目大意及思路代码运行截图收获 原题 题目大意及思路 给定图,判断输入的序列是否是拓扑序列,若不是,则记入答案数组中输出; 这个题主要参考判断和输出拓扑序列时利用入度为0的性质。 通过遍历某一结点时将除前面出现过的结点之外的以它出发的边的终点的入度减1,到最后查看入度数组是否全部为0,若否,则不是拓扑序列。 代码 #include<iostream> #include<vector> #include<queue> using namespace st

virtual_YL的博客 335

大模型面试题52:LLM如果在训练过程中loss值出现spike应该怎么办?

小白急救:停更→回滚→降LR→裁剪梯度,先保住训练不崩溃;进阶排查:查数据→查优化器→查硬件,找到spike的根因并解决;深层预防:预处理保守配置+训练中实时监控,从源头规避spike。先止损,再溯源,最后预防。

叫好与叫座虽然不是对立面,但想在同一个作品中达到双重效果很难。 1180

爆刷PAT(甲级)——之【1146】 Topological Order(25 分)——拓扑排序

艰难的英语单词:topological    英 [tɒpə'lɒdʒɪkəl        拓扑(学)的 adj. 题意:给一个网络拓扑,给出Q个序列,问哪些不是拓扑排序序列。如果不是,就输出这个序列的编号。 难点:序列的编号是从0开始的,也就是说样例的3、4表示的意思是第四个和第五个序列不是拓扑排序序列。 算法思路即:保存每个点的入度,然后对于每个序列,都扫一遍序列,如果当前节点入度不是...

Hide_in_Code 493

DICOM图像知识:深入详解DICOM的层级关系

解析DICOM的四个主要层级:Patient(患者)、Study(检查)、Series(序列)和SOP(服务-对象对),探讨它们之间的关系、各自的唯一标识符以及在实际应用中的用途

编程技术探索者,分享C/C++、C#、Java、数据库等开发经验,聚焦实战技巧与AI兴趣,助力编程爱好者成长。 3306

025、Zephyr RTOS设备树覆盖与修改

本文分享了在Zephyr RTOS中使用设备树覆盖(overlay)的实战经验。作者通过一个工业数据采集项目中GPIO无法拉高的调试案例,揭示了设备树覆盖的"叠加"本质而非简单替换。文章详细介绍了覆盖文件的正确编写方式,包括节点引用、pinctrl配置等技巧,并总结了常见陷阱如状态设置不完整、别名冲突等问题。特别强调了条件覆盖的用法和调试方法,最后提出了覆盖文件管理的五项实用原则,强调设备树覆盖是硬件与软件之间的重要契约,需要谨慎对待。全文以实际项目为背景,提供了可操作性强的技术建议。

m0_50546716的博客 38

1146 Topological Order (25 分) 拓扑排序 判定

也不写题干了,主要说说拓扑排序。 对一个有向图G,我们把满足下列要求的顶点序列叫做G的拓扑排序,一般来说,一个图的拓扑排序不唯一。 (1)拓扑排序中的,对每一个节点,它的后继节点都在该节点之后出现。 (2)如果两节点没有直接间接的前驱后继关系,则两节点在序列中先后顺序不限 (3)每个拓扑排序包含G的所有节点 有向无环图(简称DAG):没有回路的有向图叫做有向无环图。 比如下图(就是pat 甲级...

辣鸡的博客 413

STM32F103/F407/H743不同GPIO速度配置(HAL库)对应的最高速度

详细介绍了STM32F103/F407/H743不同GPIO速度配置(HAL库)对应的最高速度。

kevin1499的博客 5597

【PAT甲级】1146 Topological Order

📣专栏定位:为想考甲级PAT的小伙伴整理常考算法题解,祝大家都能取得满分!

Newin2020的博客 517

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

PAT 甲级1146 Topological Order

1146 Topological Order This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options. Input Spec

cyberickk blog 261

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

PAT 甲级 1146 Topological Order

题意:给定一个有向图,然后给定一些遍历顺序,判断是否不是拓扑排序; 思路:用一个数组保存每个节点的入读,然后用邻接表存储图,输入每个数,就判断该数的入度是否为0,如果为0,则修改每个其相邻的节点的入度即减1,否则,就认为不是拓扑排序; 代码: #include<iostream> #include<vector> using namespace std; int m...

qq_42152681的博客 163

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

1146 Topological Order——PAT甲级

使用了链式前向星存储图的边,之后就是利用copy函数依次复制入度数组的数据,然后每经过一个结点就删除该结点的出度所对结点,根据题目给出数据元素依次删除,直至出现有入度不为0的元素或者删除完毕。

flyidj的博客 969

PAT——1146 Topological Order 甲级

1146 Topological Order题目题意题解AC代码 题目 https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 题意 判断给定序列是否为拓扑序列 题解 用map<int,vector>存储每个数字指向的数字集合,同时使map<int,int>记录每个数字的入度(被指的次数) 在判断给定序列时,如果数字的入度为0,说明没有数字指向它,符合要求,同时将该数字指向的数字的入度

ljhsq的博客 232

PAT甲级题目1146 Topological Order

题目大意: 判断序列是不是拓扑排序 代码: #include <iostream> #include <vector> using namespace std; int main() { int n, m, a, b, k, flag = 0, in[1010]; vector<int> v[1010]; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) {

weixin_43801993的博客 159

PAT真题练习(甲级)1146 Topological Order (25 分)

PAT真题练习(甲级)1146 Topological Order (25 分) 原题网址:https://pintia.cn/problem-sets/994805342720868352/problems/994805343043829760 This is a problem given in the Graduate Entrance Exam in 2018: Which of th...

Be Quick & Clever & Lucky 397

pat甲级 1146 Topological Order (25分)

pat甲级 1146 Topological Order (25分) note:把测试序列看作队列容器的出序列,判断每次元素出队,入度是否为零即可; 代码: #include <iostream> #include <vector> #include <unordered_map> using namespace std; unordered_map<int,vector<int>> s; unordered_map<int,int>

qq_44992782的博客 178

PAT甲级 1146 Topological Order

浙江大学PAT题目解答内容. Contribute to ZouJiu1/PAT development by creating an account on GitHub.GitHub - ZouJiu1/PAT: 浙江大学PAT题目解答内容。

邹九的个人博客 242

PAT甲级1146 Topological Order (25 分)

1146Topological Order(25分) This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supp...

Dexter 211

PAT甲级1146 Topological Order

抓住6月的最后一天刷PAT哈哈 代码写得可能有点烂,想拓扑排序想了好久。 #include&amp;lt;stdio.h&amp;gt; #include&amp;lt;iostream&amp;gt; #include&amp;lt;algorithm&amp;gt; #include&amp;lt;vector&amp;gt; using namespace std;

gq__97的博客 264

PAT甲级 1146 Topological Order 拓扑排序

1146 Topological Order This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test each of the options. Input Spec

小龙不是蛇的博客 275

【PAT甲级A1146】Topological Order (25分)(c++)

1146 Topological Order (25分) 作者:CHEN, Yue 单位:浙江大学 代码长度限制:16 KB 时间限制:400 ms 内存限制:64 MB This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are suppo

小庄同学的博客 206
上一篇: PAT 甲级 1145  Hashing - Average Search Time
下一篇: PAT 甲级 1147  Heaps
漫浸天空的雨色
博客等级 码龄15年 1303粉丝 523原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值