自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

华师少女的梦的博客

开开心心每一天

  • 博客(70)
  • 收藏
  • 关注

原创 分块查找 确定查找位置

分块查找 确定位置

2022-11-26 20:01:13 199 1

原创 陈姥姥 dijkstra 算法 小记

陈越 数据结构 单源最短路 加入v后 为什么只影响一圈邻接点

2022-11-25 13:43:01 209

原创 浙江大学计算机与软件学院2021年考研复试上机7-4 Load Balancing (30 分)

7-4 Load Balancing (30 分)Load balancing (负载均衡)refers to efficiently distributing incoming network traffic across a group of backend servers. A load balancing algorithm distributes loads in a specific way.If we can estimate the maximum incoming traffic.

2021-09-08 19:30:33 856 2

原创 表达式转换(中缀表达式转后缀表达式)

令人讨厌的字符串处理,写完人都不好了。不想写解析了,以后有时间再来补。#include<cstdio>#include<cstring>#include<stack> using namespace std;bool isnum(char c){ if(c>='0'&&c<='9') return true; else return false;}int priority[128];void initial(){

2021-09-07 15:55:11 209

原创 7-4 Shopping With Coupons (30 分)

#include<cstdio>#include<queue>#include<algorithm>using namespace std;const int maxn = 100000;int item[maxn];int coupon[maxn];bool cmp(int a, int b){ return a>b;}struct node{ int i,j; friend bool operator < (node a, n.

2021-08-30 19:22:20 511

原创 2019浙江大学考研复试上机题 Ambulance Dispatch (30 分) floyd 解法

多源最短路算法可以采用floyd算法。本题的dijkstra算法可参看本作者之前所写的文章。如果本题采取floyd算法可以拿到26分,无法通过测试点4,测试点4属于大数据测试,floyd算法是o(n^3)的复杂度。但是针对这道仅有0.08的通过率的题目,采取floyd算法会比dijkstra要简明许多,在真实的考场上采用floyd算法会降低程序出错的概率,不失为一种实用的方法。另外,针对PAT考试,400ms基本上对应处理5亿次循环左右。另外这道题一个需要注意的点是救护点是从A-1 到 A-10,这意.

2021-08-19 19:09:59 984

原创 二叉树的非递归遍历

/* 你的代码将被嵌在这里 */void InorderTraversal( BinTree BT ){ Stack S = CreateStack(); BinTree T = BT; while(T||!IsEmpty(S)) { while(T){ Push(S,T); T = T->Left; } T = Pop(S); printf(" %c",T->Data); T = T->Right; }}void PreorderTr.

2021-08-16 18:41:19 74

原创 深度优先搜索专题

这个专题是记录罗勇军《算法竞赛入门到进阶》DFS练习题的做题感悟。poj 1416 "Shredding Company"分岔路:以“12346”为例,可能的切割点:0号位置、1号位置、2号位置、3号位置、4号位置共计5个。因此,每次深度优先就以是否在i号位置进行切割为选择。用bool cut[ ]数组来记录是否切割。终止:当5个位置的切割情况都已经确定后就终止。注意点:50 12346这个测试数据会出现这两种切割: 0、1、3号切割其余位置不切割得 43 1 2 34 6;0、1、3、

2021-03-18 16:56:37 116

原创 一起动手写个CPU

春季PAT结束了,算上这次也是第二次参加PAT了。上次是去年9月份考了89分,这次考试忘记复习区间贪心,成绩没满分白忙活。下次九月份再战吧。鉴于pta上的甲级真题和历年考研保研真题以及教材和实验指导的题库都刷了3遍了,再刷题也只能去ZOJ上去刷了,那数据结构与算法就先停一停吧,反正最基本数据结构和算法也算是比较熟悉了。接下来就开始学习组成原理的知识,学习方式应该就是按照华中科技大学谭志虎老师在mooc的课和实验来进行,这个专栏会更新我学习组原的所有实验和一些值得讨论的知识。到这个专栏结束应该能完成一个单流水

2021-03-14 15:21:07 175

原创 进阶实验6-3.5 关键活动 (30 分)

#include<cstdio>#include<vector>#include<queue>#include<stack>#define INF 65535#define MAXV 105using namespace std;int n,m,indegree[MAXV];int flex[MAXV][MAXV];struct ENode{ int w,weight; ENode(int _w, int _weight) : w(_.

2021-03-12 16:55:24 102

原创 7-4 Chemical Equation (30 分) (解释详细)

7-4 Chemical Equation (30 分)Achemical equationis the symbolic representation of a chemical reaction in the form of symbols and formulae, wherein the reactant entities are given on the left-hand side and the product entities on the right-hand side. For ..

2021-03-09 12:37:57 1990 5

原创 PAT(甲级)2020年春季考试

小结:很常规的一套题,每道题前面写一点小提示。7-1 Prime Day (20 分)The above picture is from Sina Weibo, showing May 23rd, 2019 as a very cool "Prime Day". That is, not only that the corresponding number of the date20190523is a prime, but all its sub-strings ended at the ..

2021-03-07 20:48:53 554

原创 2020浙江大学计算机与软件学院保研上机题(代码简明)

小结:这套题比2019年浙大保研上机质量高太多了。考到的知识点有深度优先搜索、并查集、优先级队列(最大最小堆)。第二题是个很有意思的题,我使用了三指针法做,应该是这道题最简单的解法而且时间复杂度是n。这套题的第二题和第四题都在卡时间复杂度,基本上暴力解法和最优解法每题会差10分左右。每个题代码都比较清晰简短所以只给一点小提示,相信能做到这套卷的都应该看得明白。7-1Standard Form of Polynomial(20分)The standard form of a polynomia

2021-03-06 11:26:31 2024 2

原创 浙江大学计算机与软件学院2019年保研上机

这套题跟2019年考研上机题难度差了几个数量级,建议完成时间不超过80分钟。7-1 Happy Numbers (20 分)Ahappy numberis defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits in base-ten, and repeat the process until t..

2021-03-04 19:57:26 432 1

原创 7-3 Left-View of Binary Tree (25 分)

7-3 Left-View of Binary Tree (25 分)Theleft-viewof a binary tree is a list of nodes obtained by looking at the tree from left hand side and from top down. For example, given a tree shown by the figure, its left-view is { 1, 2, 3, 4, 5 }Given the ino..

2021-03-04 17:23:34 212 1

原创 7-2 How Many Ways to Buy a Piece of Land (25 分)

7-2 How Many Ways to Buy a Piece of Land (25 分)The land is for sale in CyberCity, and is divided into several pieces. Here it is assumed that each piece of land has exactly two neighboring pieces, except the first and the last that have only one. One can

2021-03-04 16:57:50 160 1

原创 2020秋季甲级PAT 7-4 Professional Ability Test (30 分)

7-4 Professional Ability Test (30 分)Professional Ability Test (PAT) consists of several series of subject tests. Each test is divided into several levels. Level A is aprerequisite (前置要求)of Level B if one must pass Level A with a score no less thanS...

2021-03-04 16:19:33 1031 2

原创 2019浙江大学考研复试上机题 Ambulance Dispatch (30 分) ---测试点4

总体的解题思路:利用Dijkstra算法计算Na个救护中心与其余顶点的最短路径(时间上最短),并且保存救护中心和顶点之间的路径,若有多条也全部保存下来。当某个顶点v发出救护请求时,对于某个救护中心center,找出顶点v到center的经过街道数最少的路径。然后比较Na个救护中心中符合题意的那个救护中心(若有时间最小就就找时间最小,若时间相等就找车辆更多的救护中心,若时间都是最小且救护车数量都一样就找经过街道数最少的救护中心),当然只考虑还有救护车的救护中心。按照这个思路(Dijkstra+DF

2021-03-03 21:19:19 1298 1

原创 PAT小技巧记录(持续更新)

1、sscanf2、to_string()

2021-03-03 16:43:13 157 2

原创 2019浙江大学考研复试上机题

1.#include<cstdio>#include<cmath>#include<string>#include<vector>using namespace std;const int maxn = 20000;bool isPrime(long long x){ if(x<=1) return false; long long sqr = (int)sqrt(1.0*x); for(long long i=2; i<

2021-03-02 19:44:56 391

原创 1136 A Delayed Palindrome (20 分) bign数组开1000是不够的

bign的数组开1000是不够的,因为在边界条件下有可能在叠加的过程中位数会超过1000。在解题过程中数组要稍微开大一点,留一点冗余。#include<cstdio>#include<algorithm>#include<string>#include<iostream>using namespace std;const int maxn = 1010;//这里maxn取值大于1000struct bign{ int d[maxn]; i

2021-03-02 16:03:53 56

原创 1151 LCA in a Binary Tree (30 分) 测试点2

测试点2数据:5 5输出应该是:5 is an ancestor of 5.

2021-03-02 10:23:39 188

原创 1137 Final Grading (25 分)------记录一个错误

题目讲的是总成绩要超过60而不是期末成绩。一定要谨慎、细心的读题。#include<cstdio>#include<vector>#include<string>#include<map>#include<algorithm>#include<iostream>#include<cmath>using namespace std;struct student{ string name; int gp

2021-02-24 22:12:29 103

原创 1153 Decode Registration Card of PAT (25 分) 用printf进行输出

这道题的输出一定要用printf不能用cout,否则最后一个测试点会多接近100ms的运行时间。#include<cstdio>#include<vector>#include<map>#include<string>#include<algorithm>#include<iostream>using namespace std;struct node{ int site; int num;};struct.

2021-02-24 13:27:44 133

原创 1145 Hashing - Average Search Time (25 分)

这道题注意一点就好了,查询的范围是0到哈希表的表长。如果查询失败有两种情况:第一种是查到的一个格子,这个各子里什么都没有,那么查询失败的长度就是i+1。第二种情况是从0到哈希表长都查不到那么查询失败的长度就是哈希表长加1。#include<cstdio>#include<cmath>#include<algorithm>using namespace std;bool isPrime(int x){ if(x<=1) return false;.

2021-02-24 12:10:40 69

原创 1034 Head of a Gang (30 分) 如何对每一条边只访问一次

本题与一般的图遍历问题相区别的地方在于:对每个边仅访问一次。解决的办法是当访问到图中的某一个顶点u时,试图去访问该顶点u所有邻边,并且再访问过后就删除掉这条已经访问过的邻边,当然如果与该顶点u相连的另外一个顶点v未被访问过的话就深度优先访问v这个顶点直到所有的顶点都访问完毕。...

2021-02-19 11:13:49 75

原创 1107 Social Clusters (30 分) 给几组测试数据

63: 1 2 33: 4 5 63: 7 8 91: 11: 42: 1 4

2021-02-10 12:31:47 158

原创 1086 Tree Traversals Again (25 分)

#include<cstdio>#include<cstdlib>#include<stack>#include<vector>using namespace std;struct node{ int key; node* lchild; node* rchild;};vector<int> v;void postOrder(node* root){ if(root==NULL) return; postOrder(.

2021-02-04 20:36:49 51

原创 1103 Integer Factorization (30分) 测试点2 测试点5

我是从大数字往小数字去枚举的,如果照我这么写是过不了测试点的。因为在dfs函数中我是先做不选择该数,然后再选择该数。如果想要过测试点2的话改变这两句话的顺序即可。测试数据可以用100 5 2去跑一下。至于为什么会这样解释如下:如果不选择该数在前结果是:100 = 5^2 + 5^2 + 5^2 + 4^2 + 3^2如果选择该数在前结果是:100 = 6^2 + 4^2 + 4^2 + 4^2 + 4^2原因就是如果你的代码是不选择这个数的代码在前的话就会导致你深度优先一直到从10~6.

2021-01-30 18:28:31 433 4

原创 1100 Mars Numbers 对某些变量不进行初始化可能本地运行没有问题但是在oj上运行出现段错误

启发:在Stoi函数中,起初我忘记对ans进行初始化,在本地运行没有任何问题,但是提交到oj上就出现了段错误。以后再做题过程中如果发现本地运行没问题但是oj上出现段错误可以考虑是否是某些变量忘记初始化。#include<cstdio>#include<string>#include<iostream>#include<map>using namespace std;string low[13]={"tret","jan", "feb", ".

2021-01-29 16:19:32 169

原创 1060 Are They Equal 思路整理

总思路是把两个数都变成科学计数法然后比较有效位和指数是否相同。具体操作:(1)先要去掉前导零。如果是“000000”这种情况,去完前导零后字符串就没了,这时候要让指数e为0(2)此时可能字符串的第一位是小数点,这个时候把小数点去掉,然后找字符串中第一个不为零的字符所在的位置,并且把首个不为零的的字符前的所有零都去掉。另外每出现一个0,e--。注意有可能字符串是000.00000的情况,如果是这种情况要让e为0(3)此时字符串的第一位不是小数点而是一个非零数,去找小数点的位置然后去掉小数点,.

2021-01-29 15:36:22 76

原创 getline(cin,s)会读入缓冲区中的回车然后舍弃

#include<cstdio>#include<string>#include<iostream>using namespace std;int main(){ string s; char c; getline(cin,s); cout<<s<<"*****"; c = getchar(); printf("###%c$$$",c); }

2021-01-28 12:52:46 680

原创 1088 Rational Arithmetic (20分)

#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;LL gcd(LL a, LL b){ if(b!=0) return gcd(b,a%b); else return a;} struct fraction{ LL numer; LL denom;};fraction simp(fraction a){ LL common = gcd(abs(a.

2021-01-24 19:41:48 59

原创 1081 Rational Sum (20分)

#include<cstdio>#include<algorithm>using namespace std;typedef long long LL;struct rational{ long long c,m;};LL gcd(LL a, LL b){ if(b==0) return a; else gcd(b,a%b);}LL gys(LL a, LL b){ LL c = gcd(a,b); LL ans = (a*b)/c; return an.

2021-01-22 20:05:36 55

原创 1104 Sum of Number Segments (20分)

double在大量的累加时会失真,本题采用long double尽可能的降低失真的程度以通过测试点2(10^5级别的数据量),当然如果数据量再大可能long double 也不好用了,但是对本题精度够了。#include<cstdio>int main(){ int n; long double a; scanf("%d",&n); long double ans=0; for(int i=1; i<=n; i++){ scanf("%llf",&.

2021-01-22 12:39:43 68

原创 pat考试数据类型的选择(做1049的经验)

pat考试中在数据接近2147483647时用long long类型可最大程度避免边界数据溢出的可能性。

2021-01-21 22:08:39 115

原创 1029 Median

#include<cstdio>#include<algorithm>using namespace std;long long A[200010];long long B[200010];int main(){ int n1,n2; scanf("%d",&n1); int i,j,k; for(i=0; i<n1; i++){ scanf("%lld",&A[i]); } scanf("%d",&n2); for(i.

2021-01-20 13:44:16 57

原创 1044 Shopping in Mars(双指针法)

#include<cstdio>#include<vector>using namespace std;const int inf = 1000000000;struct shape{ int left,right;};int chain[100010];int main(){ int n,m,i,j; vector<shape> v; scanf("%d%d",&n,&m); for(i=0; i<n; i++){ .

2021-01-19 12:16:20 100

原创 1010 Radix(溢出处理,二分法)

#include<cstdio>#include<iostream>#include<string>#include<algorithm>using namespace std;typedef long long LL;int toInt(char c){ if(c>='0'&&c<='9') return c-'0'; else return c-'a'+10;}LL toDecNorm(string s,.

2021-01-19 11:11:55 158

原创 1010 Radix (25分)

#include<cstdio>#include<algorithm>#include<iostream>#include<string>using namespace std;typedef long long LL;LL inf = (1LL<<63)-1;LL toInt(char c){ if(c>='0'&&c<='9') return c-'0'; else return 10+c-'a.

2021-01-18 21:29:37 61

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除