
MOOC程序设计与算法例题
MOOC程序设计与算法,郭炜老师带着练的例题。
Tech_hysteria
We are all in the gutter,but some of us are looking at the stars.
展开
-
MOOC程序设计与算法练习题——深搜#4001抓住那头牛
题目给的范围是100000(5个0)QAQ#include <iostream>#include <cstring>#include <queue>using namespace std;#define MAX 100000int N,K;int visited[100010];struct steps{ int x; int s; ste...原创 2020-01-05 20:40:25 · 325 阅读 · 2 评论 -
MOOC程序设计与算法练习题——深搜#2815Roads
描述N cities named with numbers 1 … N are connected with one-way roads. Each road has two parameters associated with it : the road length and the toll that needs to be paid for the road (expressed in t...原创 2020-01-04 20:24:39 · 194 阅读 · 0 评论 -
MOOC程序设计与算法练习题——深搜#2815城堡
输入程序从标准输入设备读入数据。第一行是两个整数,分别是南北向、东西向的方块数。在接下来的输入行里,每个方块用一个数字(0≤p≤50)描述。用一个数字表示方块周围的墙,1表示西墙,2表示北墙,4表示东墙,8表示南墙。每个方块用代表其周围墙的数字之和表示。城堡的内墙被计算两次,方块(1,1)的南墙同时也是方块(2,1)的北墙。输入的数据保证城堡至少有两个房间。输出城堡的房间数、城堡中最大房间所...原创 2020-01-04 11:40:29 · 152 阅读 · 0 评论 -
MOOC程序设计与算法练习题——动态规划#2806最长子序列
描述我们称序列Z = < z1, z2, …, zk >是序列X = < x1, x2, …, xm >的子序列当且仅当存在 严格上升 的序列< i1, i2, …, ik >,使得对j = 1, 2, … ,k, 有xij = zj。比如Z = < a, b, f, c > 是X = < a, b, c, f, b, c >的子序列。...原创 2020-01-02 20:34:10 · 192 阅读 · 0 评论 -
MOOC程序设计与算法练习题——动态规划#2757最长上升子序列
描述一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1, ai2, …, aiK),这里1 <= i1 < i2 < … < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1,...原创 2020-01-02 16:51:29 · 339 阅读 · 0 评论 -
MOOC程序设计与算法练习题——动态规划#2760数字三角形
记忆递归型动态规划防止重复调用#include <iostream>#include <algorithm>using namespace std;#define MAX 101int maxsum[MAX][MAX];int D[MAX][MAX];int n;int getmax(int i,int j){ if(maxsum[i][j] != -1...原创 2020-01-02 11:54:53 · 131 阅读 · 1 评论 -
MOOC程序设计与算法练习题——递归#2787算24
样例输入5 5 5 11 1 4 20 0 0 0样例输出YESNO#include <iostream>#include <cmath>#define EPS 1e-6using namespace std;double a[5];bool isZero(double x){ if(fabs(x) <= EPS) return true...原创 2020-01-01 18:03:54 · 132 阅读 · 0 评论 -
MOOC程序设计与算法练习题——递归#1664放苹果
主要是确定递归边界和分类的思想(至少有一个空盘子和盘子全满)#include <iostream>using namespace std;int f(int m,int n){ if(m < n) return f(m,m); if(m == 0) return 1; if(n == 0) return 0; return f(m,n-1) + f(m-...原创 2020-01-01 11:57:53 · 141 阅读 · 0 评论 -
MOOC程序设计与算法练习题——递归#4132计算中缀表达式
中缀表达式的递归定义注意对小数的处理#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>using namespace std;double factor_value();//获得因子double term_value();//获得项do...原创 2020-01-01 11:23:54 · 187 阅读 · 0 评论 -
MOOC程序设计与算法练习题——递归#2694计算前缀表达式
前缀表达式的递归定义:一个数是一个逆波兰表达式,值为该数“运算符 逆波兰表达式 逆波兰表达式” 是逆波兰表达式 ,值为两个逆波兰表达式的值运算的结果递归法求前缀表达式,代码相当简单。#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;double ...原创 2019-12-31 20:02:16 · 348 阅读 · 0 评论 -
MOOC程序设计与算法练习题——递归#2754八皇后
递归法解决皇后问题代码较为简单,多少个皇后都一样。#include <iostream>#include <cmath>#define N 8using namespace std;//int N;int cnt = 0;int matrix[92][8];int posNqueen[100];void Nqueen(int k);int main(){...原创 2019-12-31 19:40:15 · 146 阅读 · 0 评论 -
MOOC程序设计与算法练习题——枚举#2811关灯问题
枚举——2811关灯问题二进制位运算处理该数字矩阵#include <iostream>#include <cstring>#include <string>#include <memory>using namespace std;int GetBit(char c,int i){//取字符第i位 return (c >>...原创 2019-12-31 11:31:17 · 269 阅读 · 1 评论 -
MOOC程序设计与算法练习题——枚举#2692假币问题
枚举——2692假币问题枚举分析#include <iostream>#include <cstring>#include <cstdio>using namespace std;char Left[3][7];char Right[3][7];char Result[3][7];bool IsFake(char,bool);//返回值为真表示...原创 2019-12-29 16:42:17 · 232 阅读 · 1 评论 -
MOOC程序设计与算法练习题——枚举#2977生理周期
枚举——2977生理周期注意枚举范围#include <iostream>#include <cstdio>using namespace std;int main(){ int p,e,i,d,k; cin >> p >> e >> i >> d; for(k = d + 1;(k-p) % 23; ++k)...原创 2019-12-29 15:25:41 · 192 阅读 · 0 评论 -
MOOC程序设计与算法练习题——枚举#2810完美立方
枚举—2810完美立方通过分析缩小枚举范围可以提高效率#include <iostream>#include <cstdio>using namespace std;int main(){ int N; scanf("%d",&N); for(int a = 2;a <= N; ++a) for(int b = 2;b < a; ++...原创 2019-12-29 11:49:55 · 217 阅读 · 0 评论