随笔分类 -  算法基础题目题解荟萃

拾遗部分算法题目
摘要:题目描述 呵呵,有一天我做了一个梦,梦见了一种很奇怪的电梯。大楼的每一层楼都可以停电梯,而且第ii层楼(1 \le i \le N)(1≤i≤N)上有一个数字K_i(0 \le K_i \le N)Ki​(0≤Ki​≤N)。电梯只有四个按钮:开,关,上,下。上下的层数等于当前楼层上的那个数字。当然, 阅读全文
posted @ 2020-11-22 10:38 py佐料 阅读(367) 评论(0) 推荐(0)
摘要:解法一 : #include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; char a[1000]; char b[1000]; void fun(char a[ 阅读全文
posted @ 2020-10-10 12:42 py佐料 阅读(173) 评论(0) 推荐(0)
摘要:【题目描述】 约19世纪末,在欧州的商店中出售一种智力玩具,在一块铜板上有三根杆,最左边的杆上自上而下、由小到大顺序串着由64个圆盘构成的塔。目的是将最左边杆上的盘全部移到最右边的杆上,条件是一次只能移动一个盘,且不允许大盘放在小盘的上面。这是一个著名的问题,几乎所有的教材上都有这个问题。由于条件是 阅读全文
posted @ 2020-09-12 08:31 py佐料 阅读(155) 评论(0) 推荐(0)
摘要:题目:给定两个正整数,求它们的最大公约数。 #include <iostream> #include <cstdio> using namespace std; /* 利用递归的思想求最大公约数 关键要理解第一次求最大公约数未果 之后,这时候第一次要求的最大公约数就等于 求b对a%b的最大公约数,于 阅读全文
posted @ 2020-09-11 20:24 py佐料 阅读(1701) 评论(0) 推荐(0)
摘要:任务描述 任务背景 我们在编写程序时,代码在通常情况下都是平台无关的。但是,在某些情况下,某一些代码是和平台相关的,比如 SSE intrinsics 函数(是一组函数,主要是把 x86 汇编封装成了函数,一个函数对应一个 x86 汇编)的底层实现是 x86 汇编,所以该类函数只能够在 x86 平台 阅读全文
posted @ 2020-09-11 17:42 py佐料 阅读(308) 评论(0) 推荐(0)
摘要:任务描述 任务背景 我们在编写程序时,代码在通常情况下都是平台无关的。但是,在某些情况下,某一些代码是和平台相关的,比如 SSE intrinsics 函数(是一组函数,主要是把 x86 汇编封装成了函数,一个函数对应一个 x86 汇编)的底层实现是 x86 汇编,所以该类函数只能够在 x86 平台 阅读全文
posted @ 2020-09-01 21:00 py佐料 阅读(374) 评论(0) 推荐(0)
摘要:【题目描述】 有一批易感人群住在网格状的宿舍区内,宿舍区为n*n的矩阵,每个格点为一个房间,房间里可能住人,也可能空着。在第一天,有些房间里的人得了流感,以后每天,得流感的人会使其邻居传染上流感,(已经得病的不变),空房间不会传染。请输出第m天得流感的人数。 【输入】 第一行一个数字n,n不超过10 阅读全文
posted @ 2020-08-29 08:56 py佐料 阅读(143) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> using namespace std; int fun(int n) { if(n==1) return 1; if(n==2) return 2; if(n==3) return 4; if(n>2) return fu 阅读全文
posted @ 2020-08-28 23:39 py佐料 阅读(275) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> using namespace std; int fun(int n) { if(n==1) return 1; if(n==2) return 2; if(n>2) return 2*fun(n-1)+fun(n-2); 阅读全文
posted @ 2020-08-28 23:32 py佐料 阅读(219) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> using namespace std; int fib(int n) { if(n==1 || n==2) return 1; else return fib(n-1)+fib(n-2); } int main() { i 阅读全文
posted @ 2020-08-28 23:27 py佐料 阅读(99) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> using namespace std; int d[25][25],n,m,cx,cy; long long dp[25][25]; //d数组用来记录是不是控制点(“马点”),dp数组用来记录路径数 int dir[8] 阅读全文
posted @ 2020-08-28 11:26 py佐料 阅读(480) 评论(0) 推荐(0)
摘要:/*【题目描述】 科学家在热带森林中发现了一种特殊的昆虫,这种昆虫的繁殖能力很强。 每对成虫过x个月产y对卵,每对卵要过两个月长成成虫。 假设每个成虫不死,第一个月只有一对成虫, 且卵长成成虫后的第一个月不产卵(过X个月产卵),问过Z个月以后,共有成虫多少对? 0≤X≤20, 1≤Y≤20, X≤Z 阅读全文
posted @ 2020-08-27 21:51 py佐料 阅读(1015) 评论(0) 推荐(0)
摘要:解法一:分治思想 #include <iostream>#include <cstdio>#include <algorithm>using namespace std;int n,a[200200];int fun(int l,int r){ if(l==r) return a[l]; //递归终 阅读全文
posted @ 2020-08-19 00:03 py佐料 阅读(154) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> #include <string> using namespace std; string fun() //功能单元:输入一个字符串,对它进行解密并且返回展开后的字符串 { char c; string s="",s1; w 阅读全文
posted @ 2020-08-18 10:34 py佐料 阅读(190) 评论(0) 推荐(0)
摘要://递归 #include <iostream> #include <cstdio> using namespace std; int a[100]; int fun(int n) { if(n==0) return 1; if(n==1) return 1; if(n==2) return 2; 阅读全文
posted @ 2020-08-18 08:18 py佐料 阅读(203) 评论(0) 推荐(0)
摘要:给出第二种思路下的代码:(区别在于初始化全为1,而后处理要被赦免的人) 阅读全文
posted @ 2020-08-17 10:47 py佐料 阅读(98) 评论(0) 推荐(0)
摘要:这里分别给出递推和递归的代码实现: 1.递推: 2.递归: 最后会发现递推写出的代码的复杂度是要比递归低很多的,当要求的数很大时,很明显递推是一种比较好的选择。 阅读全文
posted @ 2020-08-16 22:59 py佐料 阅读(118) 评论(0) 推荐(0)
摘要: 阅读全文
posted @ 2020-08-15 11:47 py佐料 阅读(91) 评论(0) 推荐(0)
摘要:#include <iostream> #include <cstdio> using namespace std; int n; int a[105]; int b[105]; int read() { scanf("%d",&n); for(int i=0;i<n;i++)//不能开一个变量大小 阅读全文
posted @ 2020-08-14 10:25 py佐料 阅读(173) 评论(0) 推荐(0)
摘要:#include <iostream> //核心思想在于穿墙而过 #include <cstdio> using namespace std; int main() { int n,l,p,maxv=0,minv=0; scanf("%d%d",&l,&n); for(int i=1;i<=n;i+ 阅读全文
posted @ 2020-08-13 17:48 py佐料 阅读(99) 评论(0) 推荐(0)