PAT-A1126

news/2024/10/23 7:23:37/

前几天去刷了PAT,趁热把答案记录下来供大家参考

这题完全是英语阅读题,题目读懂就能写

我考试的时候花了起码10分钟去读题,英语实在太渣

第3个测试点是个坑点,考的时候提交了11次才出来

第3个测试点:关键字:connected graph,要先判断图是否是一个连通图


#include<stdio.h>
#include<algorithm>
using namespace std;
const int INF=1000000000;
int n, m;
int G[510][510];
int degree[510]={0};//记录每个顶点的边数
bool vis[510]={false};
int num=0;
void DFS(int v){//判断图是否连通num++;vis[v]=true;for(int i=1;i<=n;i++){if(!vis[i]&&G[v][i]==1){DFS(i);}}
}
int main(){
int i, id1, id2;
int even=0, odd=0;
fill(G[0],G[0]+510*510,INF);//初始化图的每两个顶点之间都不连通
scanf("%d%d",&n,&m);
for(i=0;i<m;i++){scanf("%d%d",&id1,&id2);degree[id1]++;degree[id2]++;G[id1][id2]=G[id2][id1]=1;//1表示两个顶点间存在边
}
for(i=1;i<=n;i++){if(degree[i]%2==0)even++;else odd++;
}
DFS(1);
for(i=1;i<=n;i++){printf("%d",degree[i]);if(i<n)printf(" ");else printf("\n");
}
if(num==n&&even==n)printf("Eulerian");
else if(num==n&&odd==2)printf("Semi-Eulerian");
else printf("Non-Eulerian");return 0;
}





http://www.ppmy.cn/news/323932.html

相关文章

A1016(25)

很考察耐心的一道题&#xff0c;写起来也不是很复杂&#xff0c;耐心去做肯定是能写出来的啦 下面介绍一下auto的用法&#xff0c;比如&#xff0c;int或者double&#xff0c;我们可以写成&#xff0c;int i0&#xff1b;double k0.0&#xff0c;那么auto相当于我没有指代这个究…

PAT a1126

目的&#xff1a;判断是否是Eulerian Path 输入&#xff1a; 每个点 每个边 输出&#xff1a; 判断是哪种情况 算法&#xff1a; 用hash表统计每个点的度。如果全为偶数&#xff0c;则为Eulerian 如果有两个点的度为奇数&#xff0c;则为semi-Eulerian 如果不是以上的…

PAT A1128

AC代码如下 #include <iostream> #include <cmath>using namespace std;const int max_k210; int output[max_k]{0}; const int max_n1100; int queen[max_n]{0};bool is_solution(int n,int a[]){for(int i 0; i < n -1 ;i){for(int j i1 ; j < n ;j){if…

解决macbook pro在只有win8系统下开启AHCI的问题

背景&#xff1a; 我的macbook pro换了一块SSD&#xff0c;只安装了win8系统&#xff0c;但是因为没有开启AHCI导致系统速度严重降低&#xff0c;没错&#xff0c;是严重降低&#xff0c;因为macbook在os x系统下才会自动开启AHCI&#xff0c;所以下定决心搞定它。 所需工具&a…

A1066

没写出&#xff0c;平衡二叉树需要多练多思考多画图. 注意点&#xff1a; 1、有可能并不是根结点的左右子树未平衡&#xff0c;遇到这种情况时&#xff0c;做平衡操作后&#xff0c;需要让该节点的父亲结点指向更新后的孩子结点&#xff0c;以保证树中间不断掉. 通过它们实现&a…

PAT A1068

题目&#xff1a;https://pintia.cn/problem-sets/994805342720868352/problems/994805402305150976 我自己没编出来。我的思路是数组从小到大排序&#xff0c;然后算dp[i][j]&#xff08;第i位最大量为j的钱&#xff09;&#xff0c;得到dp后遍历所有dp[i]&#xff0c;找dp[i…

A1065 A+B and C (64bit)

1065 AB and C (64bit) &#xff08;20 分) Given three integers A, B and C in [−​​,], you are supposed to tell whether AB>C. Input Specification: The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow…

PAT a1128

目的:判断是不是Queens Puzzle 输入&#xff1a; K 例子个数&#xff0c;[1 200] N 图片大小&#xff0c;[4 1000] 输出&#xff1a; 是的输出&#xff0c;YES 不是输出&#xff0c;NO 算法&#xff1a; 不在一行好判断&#xff0c;不在一条斜线上&#xff0c;在一条…