PAT
PAT 相关算法题
DeepGoAI
欢迎学习交流!
展开
-
1003 Emergency spfa +dfs 实现以及和 dijkstra 的优先队列方法的区别
1003 Emergency (25 point(s))As an emergency rescue team leader of a city, you are given a special map of your country. The map shows several scattered cities connected by some roads. Amount of rescu...原创 2018-11-10 12:55:21 · 226 阅读 · 0 评论 -
素数判定,素数表模板
素数判定,素数表模板bool isPrim(int n){ int N = sqrt(n)+1; for(int i=2;i<=N;i++ ){ if(n%i==0) return false; } return true;}int main(){ ll a; scanf("%d",&a); bool if_ = isPrim(a...原创 2019-08-24 22:39:59 · 167 阅读 · 0 评论 -
分数加减乘除模板
分数加减乘除模板#include<cstdio>#include<cmath>#include<iostream>using namespace std;typedef long long ll;struct Fraction{ ll up,down;};int gcd(int a,int b){ return b==0? a: g...原创 2019-08-25 13:03:39 · 527 阅读 · 0 评论 -
加减乘除实现模板
加减乘除实现模板:只实现了加减乘除四则运算#include<queue>#include<stack>#include<cstdio>#include<map> #include<iostream>using namespace std;struct node{ double num; char oper; ...原创 2019-08-27 14:18:06 · 443 阅读 · 0 评论 -
平衡二叉树模板
平衡二叉树模板#include<iostream>using namespace std;struct node{ int data,height; node* left; node* right;};node* newNode(int data){ node* root = new node; root->data = data; root-&g...原创 2019-08-30 12:48:05 · 204 阅读 · 0 评论 -
并查集模板
并查集模板#include<iostream>using namespace std;int father[1000];int level[1000];void init(int N){ for(int i=1;i<=N;i++){ father[i] = i; level[i] = 1; }}int getFather(int i){...原创 2019-08-30 13:04:28 · 216 阅读 · 0 评论 -
PAT A1034 邻接表实现
PAT A1034 邻接表实现实现思路参考 《算法笔记》P354#include<iostream>#include<vector>#include<map>#include<algorithm>#include<cstring>using namespace std;const int MAXN = 10000;...原创 2019-08-30 22:32:47 · 199 阅读 · 0 评论 -
PAT A1076 Forwards on Weibo
PAT A1076 Forwards on Weibo#include <iostream>#include<vector> #include<queue> #include<cstring>using namespace std;const int MAXN = 10000;vector<int> map_[MAX...原创 2019-08-31 22:30:32 · 218 阅读 · 0 评论 -
dijkstra 算法优先队列实现
dijkstra 算法优先队列实现基于优先队列的算法实现其实很简单,首先,我们要清楚dijkstra 算法的核心思想:n次查找: 1.每次查找距离起点s最近的 且未访问的顶点 u ,dist[u] 表示距离起点的最近的点的距离 2.for(从 u 出发能到达的所有的顶点v): if(以 u 为中介点 能够使得 s 到顶点v的最短距离d[v]...原创 2019-09-02 19:40:52 · 2186 阅读 · 0 评论 -
PAT A1030 Travel Plan
PAT A1030 Travel Plandijkstra 优先队列实现 + dfs#include<iostream>#include<queue>#include<vector>#include<cstdio>#include<cstring>using namespace std;const int ...原创 2019-09-03 13:55:18 · 180 阅读 · 0 评论 -
质因数分解模板
质因数分解模板#include<cstdio>#include<cmath>#include<iostream> using namespace std;int p[1000];int num[1000];bool isPrim(int n){ int N = sqrt(n)+1; for(int i=2;i<=N...原创 2019-08-24 22:38:06 · 278 阅读 · 0 评论 -
随机选择算法
随机选择算法算法笔记随机选择算法 P149#include<iostream>#include<cstdio>#include<algorithm>#include<ctime>#include<cmath>using namespace std;#include<vector>int Ar...原创 2019-08-23 22:36:24 · 229 阅读 · 0 评论 -
1014 Waiting in Line (30 point(s))
1014 Waiting in Line (30 point(s))Suppose a bank has N windows open for service. There is a yellow line in front of the windows which devides the waiting area into two parts. The rules for the cu...原创 2018-11-28 21:20:09 · 169 阅读 · 0 评论 -
1004 Counting Leaves (30 point(s))
1004 Counting Leaves (30 point(s))A family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.Input Specification:Each input file cont...原创 2018-11-11 22:30:23 · 288 阅读 · 0 评论 -
1005 Spell It Right (20 point(s))
1005 Spell It Right (20 point(s))Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each inp...原创 2018-11-12 20:36:15 · 187 阅读 · 0 评论 -
1006 Sign In and Sign Out (25 point(s))
1006 Sign In and Sign Out (25 point(s))At the beginning of every day, the first person who signs in the computer room will unlock the door, and the last one who signs out will lock the door. Given t...原创 2018-11-12 21:24:59 · 167 阅读 · 0 评论 -
1003 Emergency (25 point(s))
1003 Emergency (25 point(s))SPFA 部分未通过 19分思路:1.SPFA可以在有路径长度为负的情况下,也能够实现最短路径2.需要一个距离数组 d 对应的表示该源到图中所有点的最短距离 初始设为INF3.需要一个是否在队列的判定数组4.需要一个每个节点入队次数的数组,因为可能有负环,所以要做好控制,另外,因为最短路径其实是可以生成最短路径...原创 2018-11-14 20:04:23 · 336 阅读 · 0 评论 -
1007 Maximum Subsequence Sum (25 point(s))
1007 Maximum Subsequence Sum (25 point(s))部分未通过 22分#include<iostream>#include<vector>#include<algorithm>using namespace std;struct node{ long long start; long long ...原创 2018-11-14 20:06:14 · 115 阅读 · 0 评论 -
1009 Product of Polynomials (25 point(s))
1009 Product of Polynomials (25 point(s))This time, you are supposed to find A×B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies ...原创 2018-11-14 21:25:43 · 178 阅读 · 0 评论 -
1012 The Best Rank (25 point(s))
To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - Eng...原创 2018-11-22 10:43:32 · 216 阅读 · 0 评论 -
1010 Radix (25 point(s))
1010 Radix (25 point(s))Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is yes, if 6 is a decimal number and 110 is a binary number.Now for...原创 2018-11-19 22:23:52 · 262 阅读 · 0 评论 -
1013 Battle Over Cities (25 point(s))
1013 Battle Over Cities (25 point(s))It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are clo...原创 2018-11-25 21:13:19 · 111 阅读 · 0 评论 -
prim 最小生成树优先队列实现
prim最小生成树优先队列实现#include<iostream>#include<vector>#include<queue>#include<set>using namespace std;int N,M;struct node{ int to,len; node(){} node(int to,int len):t...原创 2019-09-05 14:02:01 · 866 阅读 · 0 评论