PAT
wlop98
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
PAT甲级 DFS BFS总结
树的遍历 1090 Highest Price in Supply Chain (25 分) #include<bits/stdc++.h> using namespace std; int depth[100000];//结点的深度 vector<int> v[100000];//存放树 int root; void dfs(int father) { for(int each:v[father]){ depth[each]=depth[father]+1原创 2021-07-23 22:32:38 · 287 阅读 · 0 评论 -
PAT甲级 二叉树题总结
1086 Tree Traversals Again (25 分) #include<bits/stdc++.h> using namespace std; struct node{ int data; node*l,*r; }; int post[50],in[50],pre[50]; node* cratenode(int p1,int p2,int i1,int i2) { if(p1>p2)return NULL; node* root=new n原创 2021-07-16 23:39:19 · 309 阅读 · 1 评论 -
1051 Pop Sequence (25 分)
原题 Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, …, N and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if M is 5 and N is 7, we can obt原创 2021-05-03 19:31:09 · 141 阅读 · 0 评论 -
7-40 列车调度
题目描述 火车站的列车调度铁轨的结构如下图所示。 两端分别是一条入口(Entrance)轨道和一条出口(Exit)轨道,它们之间有N条平行的轨道。每趟列车从入口可以选择任意一条轨道进入,最后从出口离开。在图中有9趟列车,在入口处按照{8,4,2,5,3,9,1,6,7}的顺序排队等待进入。如果要求它们必须按序号递减的顺序从出口离开,则至少需要多少条平行铁轨用于调度? 输入格式: 输入第一行给出一个整数N (2 ≤ N ≤105 ),下一行给出从1到N的整数序号的一个重排列。数字间以空格分隔。 输出格原创 2021-04-06 17:06:47 · 343 阅读 · 0 评论 -
全排列 (递归)
{1,2,3}的全排列 源码 #include<iostream> using namespace std; const int maxn=11; int n,p[maxn],hashTable[maxn]={false}; void generateP(int index) { if(index==n+1) { for(int i=1;i<=n;i++) { cout<<p[i]; }原创 2021-03-01 21:32:03 · 203 阅读 · 0 评论 -
PAT 1059 Prime Factors (25 分)
原题 code #include <iostream> #include <cmath> using namespace std; const int maxn = 100010; bool isprime(int n) //判断是否为素数 { if (n == 1) return false; int sqr = (int)sqrt(1.0 * n); for (int i = 2; i <= sqr; i++) {原创 2021-02-21 14:06:23 · 157 阅读 · 0 评论 -
求最大公约数 (欧几里得算法/辗转相除法)
定理 欧几里得算法基于以下定理: 设a、b均为正整数,则gcd(a,b)=gcd(b,a%b); 源码 #include <cstdio> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } int main() { int m, n; while (scanf("%d%d", &m,原创 2021-02-20 16:57:41 · 260 阅读 · 0 评论 -
牛客 1018 A+B in Hogwarts
分析 主要就是输入的问题,3.2.1中的小数点,这里采用了char类型的c过渡。 代码 #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { int g[2],s[2],k[2]; char c; cin>>g[0]>>c>>s[0]>>c>>k[0]; cin&.原创 2021-02-18 13:11:08 · 184 阅读 · 0 评论 -
PAT 1002 A+B for Polynomials
原题 思想 这题踩了输出格式的坑,精度得保留小数点后一位。 设置小数位数法: cout<<setiosflags(ios::fixed)<<setprecision(1); 当setiosflags(ios::fixed)和serprecision(n)两个一起用时就表du示保留n位小数输出。这里还要注意,每次输出只要设置一次就行了,因为这两个的作用范围是后续对象,而不是仅对后一个对象起作用。 这里我用了2种方法。 方法一采用i,j指针分别控制A和B,判断系数相等和不相等的情况原创 2021-01-30 22:36:58 · 162 阅读 · 0 评论 -
PAT A+B Format 1001
题目 Calculate a+b and output the sum in standard format – that is, the digits must be separated into groups of three by commas (unless there are less than four digits). Input Specification: Each input file contains one test case. Each case contains a pair o原创 2020-07-13 20:57:58 · 210 阅读 · 0 评论
分享