1126 Eulerian Path (25 point(s))

5.2-8.矩阵转置【1.8编程基础之多维数组09】 8.矩阵转置【1.8编程基础之多维数组09】 输入一个n行m列的矩阵A,输出它的转置AT。 输入: 第一行包含两个整数n和m,表示矩阵A的行数和列数(1<=n<=100,1<=m<=100)。 接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。 输出: m行,每行n个整数,为矩阵A的转置。相邻两个整数之间用单个空格隔开。 样例输入: 3 3 1 2 3 4 5 6 7 8 9 样例输出: 1 4 7 2 5 8 3 6 9 阅读详情

 1126 Eulerian Path (25 point(s))

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were first discussed by Leonhard Euler while solving the famous Seven Bridges of Konigsberg problem in 1736. It has been proven that connected graphs with all vertices of even degree have an Eulerian circuit, and such graphs are called Eulerian. If there are exactly two vertices of odd degree, all Eulerian paths start at one of them and end at the other. A graph that has an Eulerian path but not an Eulerian circuit is called semi-Eulerian. (Cited from https://en.wikipedia.org/wiki/Eulerian_path)

Given an undirected graph, you are supposed to tell if it is Eulerian, semi-Eulerian, or non-Eulerian.

Input Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N (≤ 500), and M, which are the total number of vertices, and the number of edges, respectively. Then M lines follow, each describes an edge by giving the two ends of the edge (the vertices are numbered from 1 to N).

Output Specification:

For each test case, first print in a line the degrees of the vertices in ascending order of their indices. Then in the next line print your conclusion about the graph -- either Eulerian, Semi-Eulerian, or Non-Eulerian. Note that all the numbers in the first line must be separated by exactly 1 space, and there must be no extra space at the beginning or the end of the line.

Sample Input 1:

7 12
5 7
1 2
1 3
2 3
2 4
3 4
5 2
7 6
6 3
4 5
6 4
5 6

Sample Output 1:

2 4 4 4 4 4 2
Eulerian

Sample Input 2:

6 10
1 2
1 3
2 3
2 4
3 4
5 2
6 3
4 5
6 4
5 6

Sample Output 2:

2 4 4 4 3 3
Semi-Eulerian

Sample Input 3:

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

Sample Output 3:

3 3 4 3 3
Non-Eulerian

欧拉路径、欧拉回路的判断。

思路:先判断是否是连通图(并查集或者DFS),再统计每个结点的度。

参考链接:https://blog.youkuaiyun.com/richenyunqi/article/details/80169214

#include<iostream>
#include<cstring>
using namespace std;
const int MAX = 507;
int cnt[MAX]={0};
int Tree[MAX];
int N,M;
int findRoot(int x){
	if(Tree[x]==-1) return x;
	else{
		int temp = findRoot(Tree[x]);
		Tree[x] = temp;
		return temp;
	}
}
int main(void){
	cin>>N>>M;int a,b;
	memset(Tree,-1,sizeof(Tree));
	while(M--){
		cin>>a>>b;
		cnt[a]++;
		cnt[b]++;
		int na = findRoot(a);
		int nb = findRoot(b);
		if(na!=nb){
			Tree[na]=nb;
		}//并查集,检查是否只有一个连通分支 
	}
	int k=0;
	for(int i=1;i<=N;i++){
		if(Tree[i]==-1) k++;
	}//计算连通分支数 
	for(int i=1;i<=N;i++){
		if(i==1) cout<<cnt[i];
		else cout<<" "<<cnt[i]; 	
	}
	cout<<endl;
	if(k==1){//如果连通 
		int odd=0;
		for(int i=1;i<=N;i++){
			if(cnt[i]%2!=0)  odd++;
		}
		if(odd==0) cout<<"Eulerian";
		else if(odd==2) cout<<"Semi-Eulerian";
		else cout<<"Non-Eulerian";
	}
	else cout<<"Non-Eulerian";
	
	return 0;
}

 

算法-矩阵转置(信息学奥赛一本通-T1126)(包含源程序).rar 立即下载

相关推荐

STM32 烧录报错Invalid ROM Table

STM32 烧录报错Invalid ROM Table

热爱科技,物联,程序开发等 1735

C++信息学奥赛1126:矩阵转置

这段代码的功能是输入一个二维数组 arr,然后按列顺序输出该数组的元素。整个代码的作用是按列顺序输出二维数组 `arr` 的元素。每列的元素由上到下依次输出,并且元素之间用空格分隔,每列输出完后换行。

qq_45083002的博客 795

Simulink仿真避坑指南:如何设置步长、powergui和模块采样时间才能让控制周期更稳定

本文深入解析Simulink仿真中步长、powergui和模块采样时间的协同配置方法,帮助工程师解决控制周期不稳定问题。通过实际案例和参数调优技巧,指导用户精准设置仿真参数,确保电机控制、电力电子系统等工业仿真结果的可靠性。

weixin_42524762的博客 419

矩阵转置输入

题目: 一个n行m列的矩阵A,输出它的转置AT。 输入: 第一行包含两个整数n和m,表示矩阵A的行数和列数(1<=n<=100,1<=m<=100)。 接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。 输出: m行,每行n个整数,为矩阵A的转置。相邻两个整数之间用单个空格隔开。 样例输入: 3 3 1 2 3 4 5 6 7 8 9 样例输出: 1 4 7 2 5 8 3 6 9 示例: public class Demo03

爱学习的大雄的博客 640

RSA算法详解:万字文章详解RSA的加密与解密

为了彻彻底底的研究明白RSA算法,真的是。。煞(lei)费(si)苦(wo)心(le),首先我希望自己前前后后、彻彻底底的琢磨明白,其次我也希望我把他分享出来以后,大家都能读得懂,这篇文章真的是我迄今为止写的又臭又长的一篇文章了,但是我能保证的是,你读完了以后,绝对不会再问RSA是啥玩意儿了。。

布啦啦 7668

Allegro如何设置走线自动删除重复走线操作指导

Allegro如何设置走线是自动删除重复走线操作指导在PCB布线的时候,点到点需要重复走一段线的时候,希望原来的线段自动被删除,Allegro设计的时候支持这个操作如下图,重复走中间的线段的时候,希望下方的走线自动删除具体操作如下This section is describe what the function allegro have ,helpfully could let user know more about allegroAllegro Design and Analysis includes

weixin_54787054的博客 4499

矩阵转置(信息学奥赛一本通-T1126)

【题目描述】 输入一个n行m列的矩阵A,输出它的转置A^T。 【输入】 第一行包含两个整数n和m,表示矩阵A的行数和列数(1≤n≤100,1≤m≤100)。 接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。 【输出】 m行,每行n个整数,为矩阵A的转置。相邻两个整数之间用单个空格隔开。 【输入样例】 3 3 1 2 3 4...

Alex_McAvoy的博客 1万+

使用 SAP 自家的 AI 工具 Joule 辅助 SAP Fiori 应用开发

SAP Joule 不请自答,解释说标记了接口的 UI Component,具备进行异步内容创建的能力,比如其通过 rootView 分配的视图,在运行时可以异步创建。目前 SAP Business Application Studio 里的 SAP Joule 支持下面这八种上下文,绝大部分都和 SAP UI5 开发相关,剩下的则是代码仓库和 SAP 帮助文档的搜索。SAP Joule 回答的大意是:我只负责回答 SAP UI5 开发相关的问题,不要和我扯其他有的没的。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 1096

信息学奥赛一本通:1126:矩阵转置

接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。第一行包含两个整数n和m,表示矩阵A的行数和列数(1

u014117969的博客 1076

STM32F103(二十三)通用同步异步收发器(USART)

学习板:STM32F103ZET6 往期博客: STM32F103五分钟入门系列(一)跑马灯(库函数+寄存器)+加编程模板+GPIO总结 STM32F103五分钟入门系列(二)GPIO的七大寄存器+GPIOx_LCKR作用和配置 STM32F103五分钟入门系列(三)GPIO的常用库函数使用方法总结+一个网络上的误区 STM32F103五分钟入门系列(四)蜂鸣器实验(库函数+寄存器) STM32F103五分钟入门系列(五)按键实验(库函数+寄存器) STM32F103五分钟入门系列(六)时钟框图+相关寄存器

Curnane0_0的博客 1019

docker部署neo4j,设置密码。Neo.ClientError.Security.Unauthorized: The client is unauthorized due to authenti

卷,设置NEO4J_AUTH将不会起作用,因为该数据库已经配置了身份验证。Neo4j Docker 服务将会启动,但您需要使用已与该数据库关联的用户名和密码才能登录。这里,使用了环境变量NEO4J_AUTH,设置了用户名为neo4j,密码为neo4jneo4j。这个命令还是比较全的,包括设置密码,设置端口,挂载外部的数据目录等。原因嘛,就是使用docker创建的neo4j,登录不上。把👆提到的外挂的数据,都清空了,再重新来一遍。有一种情况下,这样设置密码,并不会成功。如果不出意外,目前就算大功告成了。

xiezhipu的博客 564

1126 Eulerian Path (25 point(s))

#include&lt;iostream&gt; #include&lt;cstdio&gt; #include&lt;queue&gt; #include&lt;vector&gt; using namespace std; const int MAXN = 510; bool vis[MAXN]; vector&lt;vector&lt;int&gt;&gt; e; int n, ev...

徐伯莱 246

fanuc机器人KAREL中 函数的应用

本次课程讲解编程的思路。很多的同学都玩过积木,一个一个的模块逐渐累积起来,通过彼此之间的相互联系,最终形成一个完整的整体。其实编程也是这样。 将一个对象根据其特点进行模块化拆分,尤其是一些特点非常相似的内容,将其变成一个模块。然后通过传递参数,实现不同的功能,这就是模块化编程。

haier123888的博客 2744

1126 Eulerian Path (25 point(s))

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were firs...

张蔡辉 195

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

【PAT】A1126 Eulerian Path (25point(s))

文章目录A1126 Eulerian Path (25point(s))Input Specification:Output Specification:Sample Input 1:Sample Output 1:Sample Input 2:Sample Output 2:Sample Input 3:Sample Output 3:CodeAnalysis Author: CHEN, Yue...

Duke 267

OV9734 DATASHEET,完整规格书

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

PTA甲1126 Eulerian Path (25 point(s))

强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写成 柳神的优快云博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全名是 算法笔记 上级训练实战指南 //这本都是PTA的题解算法笔记 PS 今天也要加油鸭 一些有意思的彩蛋: 这题在写之前强烈推荐看下这个视频,个人觉得蛮有意义的,描述了图论的起源 欧拉路径 题目原文 In graph theory, an Eulerian path is a path in a gr

Huangpengyu123的博客 382

WINCC7.3破解文件

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

1126 Eulerian Path (25point(s)) - C语言 PAT 甲级

关键词:欧拉图,并查集 先用并查集判断是否为联通图,若是连通图再继续判断欧拉图 1. Eulerian(欧拉图):联通图,每个节点度为偶数 2. Semi-Eulerian(半欧拉图):连通图,只有两个节点度为奇数,其他均为偶数 3. Non-Eulerian:既不是欧拉图也不是半欧拉图

有三只土豆 220

1126 Eulerian Path (25point(s)) 欧拉图的判定+连通图的判定dfs

题目 题目链接 思路 欧拉图:对于一个连通图,如果从一个顶点出发,把图中每条边仅走一次,最后回到出发点即为欧拉图(著名的七桥问题); 欧拉图性质:每个顶点的度都是偶数; 先把图用邻接表存起来,然后用dfs判断是否是连通图(一定要判断是否是连通图,否则有一个测试点过不去); dfs的过程中,统计度为奇数顶点的个数,然后根据题意输出就可以了; 代码 #include <iostream> #include <vector> #include <cstring> using

hjyp的博客 489

PAT(A) 1126 Eulerian Path (25 point(s))

#include<bits/stdc++.h> using namespace std; int N, M, cntCnn = 0, cntOdd = 0; vector<vector<int>> v; vector<int> cntDgr, vis; void dfs(int index){ vis[index] = 1; for(int i = 0; i < v[index].size(); i++) if(vis

Anpotan的博客 88

PAT_甲级_1126 Eulerian Path (25point(s)) (C++)【欧拉图】

目录 1,题目描述 题目大意 输入 输出 欧拉图 2,思路 3,AC代码 4,解题过程 第一搏 第二搏 第三搏 1,题目描述 Sample Input 1: 7 12 5 7 1 2 1 3 2 3 2 4 3 4 5 2 7 6 6 3 4 5 6 4 5 6 Sample Output 1: 2 4 4 4 4 4 2 Eulerian Sam...

&再见萤火虫&的博客 386

1126 Eulerian Path(25 分)(C++)

In graph theory, an Eulerian path is a path in a graph which visits every edge exactly once. Similarly, an Eulerian circuit is an Eulerian path which starts and ends on the same vertex. They were firs...

qq_41562704的博客 434

1126 Eulerian Path (25分)——C语言实现(含测试三错误原因)

对于无向图来说,若结点度数都是偶数,则是欧拉图;若结点度数有两个奇数,其余为偶数,则为半欧拉图;其他情况不是欧拉图。

Layman的博客 413

PAT 甲级 1126 Eulerian Path

题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805349851185152 判断是不是欧拉图,也就是判断一个图的边能不能一笔画下来,如果能一笔画下来并且连到起始点的话输出Eulerian,如果能一笔画下来但是不能连到起始点的话,输出 semi-Eulerian ,其他情况输出Non-Eulerian 题目里面给...

HOYITIO的博客 297

1126:矩阵转置(C C++)

【题目描述】 输入一个n行m列的矩阵A,输出它的转置A^T。 【输入】 第一行包含两个整数n和m,表示矩阵A的行数和列数(1≤n≤100,1≤m≤100)。 接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。 【输出】 m行,每行n个整数,为矩阵A的转置。相邻两个整数之间用单个空格隔开。 【输入样例】 3 3 1 2 3 4 5 6 7 8 9 【输出样例】 1 4 7 2 5 8 3 6 9 【代码】 ...

ネロ・クラウディウス 3582

1126:矩阵转置

接下来n行,每行m个整数,表示矩阵A的元素。相邻两个整数之间用单个空格隔开,每个元素均在1~1000之间。第一行包含两个整数n和m,表示矩阵A的行数和列数(1

在下的博客 277
上一篇: 1125 Chain the Ropes (25 point(s))
下一篇: 1127 ZigZagging on a Tree (30 point(s))
coderwait
博客等级 码龄9年 20粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值