- 博客(14)
- 收藏
- 关注
原创 打印循环赛日程表
循环赛日程表赛制要求如下:循环赛日程表问题,设有n=2k个选手要进行循环赛,设计一个满足以下要求的比赛日程表:每个选手必须与其他n-1个选手各赛一次;每个选手一天只能赛一次;循环赛一共进行n-1天。打印结果#include <iostream>using namespace std;#define MAX 100int a[MAX][MAX];void ...
2019-10-09 09:27:06
623
原创 区间合并问题
区间合并问题给定 n 个闭区间 [ai; bi],其中i=1,2,…,n。任意两个相邻或相交的闭区间可以合并为一个闭区间。例如,[1;2] 和 [2;3] 可以合并为 [1;3],[1;3] 和 [2;4] 可以合并为 [1;4],是[1;2] 和 [3;4] 不可以合并。运用分治的思想#include <iostream>#include <algorithm>...
2019-10-09 09:18:40
669
原创 计算众数和重数问题
这个当时写了注释#include<iostream>#include<algorithm>using namespace std;int n1=0; //定义全局变量用来定义众数int n2=0; //用来定义重数int count(int a[],int first,int last){//firsrt为数组第一个元素 last表示数组a的最后一个元素...
2019-10-09 08:30:03
763
原创 气球问题
迭代器的小应用气球问题????#include<iostream>#include<map>#include<iterator>#include<string>using namespace std;int main(){ int n,max = 0; while (cin>> n && n &g...
2019-10-07 10:29:37
869
原创 正序输出每一位数
正整数 N#include<iostream>using namespace std;void Reverse(int n){ if( n/10 == 0 ) cout<<n; else { Reverse( n/10 ); cout<<" "; cout<<n%10; ...
2019-10-07 10:24:57
813
原创 解决整数划分问题
不好意思 刚刚看到代码块这个功能#include<iostream>using namespace std;int zshf(int n,int m){ //最大加数n不大于m的划分个数记作q(n,m) if( n < 1) return 0; else if( n == 1 || m == 1 ) return 1; //类似于1+1+1+。。这种情况...
2019-10-07 10:23:38
215
原创 数字三角形顺推法
不好意思上一个文章少了一个字 数字三角形#includeusing namespace std;int main(){int n,i,j,a[100][100];cout<<"n = ";cin>>n;cout<<“请输入数字三角形的值:”;for( i = 1;i <= n; i++ )for(j = 1; j <= i; j++...
2019-10-07 10:20:37
272
原创 数字三角形逆推法
用到了的数组比较大 大家可以自行设置所需数组大小#include #include using namespace std;const int MAXN = 1005;int A[MAXN][MAXN],F[MAXN][MAXN],N;int max(int a,int b){if(a>b) return a;return b;}int main() {int i,j...
2019-10-07 10:19:16
342
原创 递归解决全排列问题
代码#includeusing namespace std;void Perm(int list[], int k, int m){if(k==m){for(int i=0;i<=m;i++)cout<<list[i]<<" ";cout<<endl;}elsefor(int j=k;j<=m;j++) {swap(list[...
2019-10-07 10:17:14
218
原创 求N层汉诺塔的移动次数
贴代码#includeusing namespace std;int main(){int f[1000]={0,1};int n;cout<<"n = ";cin>>n;for(int i = 2;i <= n; i++){f[i] = 2*f[i-1] + 1;}cout<<“移动次数为:”<<f[n]<<...
2019-10-07 10:15:27
1265
原创 菲波那契数列的前 n 项
代码#includeusing namespace std;int main(){int i,n,a0,a1;cout<<"n = “;cin>>n;a0 = 0; a1 = 1;cout<<a0<<” “<<a1<<” “;for(i = 2;i <= n/2; i++){a0 = a0 + a1;...
2019-10-07 10:12:18
199
原创 递归将10进制转化成radix进制
代码#includeusing namespace std;void change(int num,int radix){if(num != 0 ){change(num/radix , radix); //递归cout<< num%radix; //返回余数}}int main(){int n,radix;cin>>n>>radix;c...
2019-10-07 10:08:55
299
原创 递归解决猴子吃桃问题
代码#includeusing namespace std;int f( int day){if( day == 10) return 1;else return (f(day + 1) + 1) * 2;}int main(){cout<<“第一天桃子的数量为:”<<f(1)<<endl;return 0;}写的略显简单...
2019-10-07 10:06:56
538
原创 递归解决汉诺塔问题
#不说别的 直接代码代码#includeusing namespace std;void move(char from , char to ){cout<<"Move “<<from<<” to "<<to<<endl;}void hannuo(int n,char first,char second,char third)...
2019-10-07 10:04:54
255
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人