经典算法(61~90)

注:已选择性忽略绘图部分

【程序61】(利用二维数组
题目:打印出杨辉三角形(要求打印出10行如下图)
1.程序分析:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1

 1 #include<stdio.h>
 2 main()
 3 {
 4     int a[10][10];
 5     int i, j, k;
 6     for( i=0; i<9; i++)
 7     {
 8         for( k=0; k<10-i; k++)
 9             printf("  ");
10         for( j=0; j<=i; j++)
11         {
12             if(j==0 || j==i)
13                 a[i][j]=1;
14             else
15                 a[i][j]=a[i-1][j-1]+a[i-1][j];
16             printf("%d   ",a[i][j]);
17         }
18         printf("\n");
19     }
20     system("pause");
21 }

==============================================================
【程序62】 (略)
题目:学习putpixel画点。

==============================================================
【程序63】 (略)
题目:画椭圆ellipse

==============================================================
【程序64】 (略)
题目:利用ellipse and rectangle 画图。

==============================================================
【程序65】 (略)
题目:一个最优美的图案。

==============================================================
【程序66】 (回顾指针,实现2个数交换)
题目:输入3个数a,b,c,按大小顺序输出。

 1 #include<stdio.h>
 2 void swap(int *p1, int *p2)
 3 {
 4     int p;
 5     if(*p1<*p2)
 6     {
 7         p=*p1;    *p1=*p2;    *p2=p;
 8     }
 9 }
10 main()
11 {
12     int a,b;
13     int *p1, *p2;
14     p1=&a;
15     p2=&b;
16     scanf("%d%d", &a,&b);
17     if(a<b)
18         swap(p1,p2);
19     printf("%d     %d\n",*p1, *p2);
20     system("pause");
21 }

==============================================================
【程序67】(本质冒泡排序) 
题目:输入数组,最大的与第一个元素交换,最小的与最后一个元素交换,输出数组。

#include<stdio.h>
#define N 10
main()
{
    int a[N]={1,2,3,4,5,6,7,8,9,10};
    int i, j;
    for( i=0; i<N-1; i++)
    {
        for( j=i+1; j<N; j++)
        {
            if( a[i]<a[j])
            {
                a[i]=a[i]^a[j];
                a[j]=a[i]^a[j];
                a[i]=a[i]^a[j];
            }
        }
        printf("%d  ",a[i]);
    }
    printf("%d", a[N-1]);
    getchar();
}

==============================================================
【程序68】 (取模运算)
题目:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数

 1 #include<stdio.h>
 2 #define N 10
 3 main()
 4 {
 5     int a[N]={1,2,3,4,5,6,7,8,9,10};
 6     int tmp[N];
 7     int m;
 8     int i, j, temp;
 9     scanf("%d", &m);
10     for( j=0; j<m; j++)
11         {
12             tmp[j]=a[j];
13             //printf("temp[%d]=%d\n", j, tmp[j]);
14         }
15     for( i=0; i<N; i++)
16     {
17         if( (i+m)>=N)
18             a[i]=tmp[(i+m)%N];            //考虑溢出,取余循环
19         else
20             a[i]=a[i+m];                    //简单移位
21         printf("%d  ", a[i]);
22     }
23     system("pause");
24 }

==============================================================
【程序69】
题目:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出
圈子,问最后留下的是原来第几号的那位。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAX 100+1
 4 main()
 5 {
 6     int n;
 7     int a[MAX];
 8     int i, temp, count;
 9     for( i=1; i<MAX; i++)
10         a[i]=1;
11     scanf("%d", &n);
12     temp=n;
13     count=0;
14     i=1;
15     for( ; ; )
16     {
17         //printf("loop\n");
18         if(n==1)
19             break;
20         if( i!=0)
21         {
22             if( a[i]==1)
23             {
24                 count++;
25                 //printf("i=%d, count=%d\n", i, count);
26                 //a[i]=0;
27                 if(count%3==0)
28                 {
29                     count=0;
30                     a[i]=0;
31                     n--;
32                     printf("delete:%d\nn=%d\n", i, n);
33                 }
34             }
35             i=(i+1)%(temp+1);
36             //printf("i=%d\n",i);
37         }
38         else
39             i++;
40         }
41     for( i=1; i<=temp; i++)
42     {
43         if(a[i]==1)
44             printf("result=%d\n", i);
45     }
46     system("pause");
47 }

==============================================================
【程序70】 (字符串处理)
题目:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define MAXN 100+1
 4 int count(char *p);
 5 main()
 6 {
 7     char *p[100];                            //关于此处定义方法不是特别清楚
 8     scanf("%s" , p);                         //输入不能超过100字符
 9     printf("%d\n", count(p));
10     system("pause");
11 }
12 int count( char *p)
13 {
14     int num=0;
15     while(*p!='\0')
16     {
17         p++;
18         num++;
19     }
20     return num;
21 }

【程序71】 (结构体声明的格式及注释)
题目:编写input()和output()函数输入,输出5个学生的数据记录。

 1 #include<stdio.h>
 2 #define N 2
 3 struct Student
 4 {
 5     char name[10];        //char *name[10]区别
 6     char no[10];
 7     int age;
 8 }stu[N];                    //此处有疑问
 9 
10 void input()
11 {
12     int i;
13     for( i=0; i<N; i++)
14     {
15         printf("Please input the name of student %d: ", i+1);
16         scanf("%s", stu[i].name);
17         printf("Please input the number of student %d: ", i+1);
18         scanf("%s", stu[i].no);
19         printf("Please input the age of student %d: ", i+1);
20         scanf("%d", &stu[i].age);
21     }
22 };
23 void output()
24 {
25     int i;
26         printf("Information about student :\n");
27         printf("  name    number age\n");
28     for( i=0; i<N; i++)
29         printf("%d: %s    %s    %d\n", i+1, stu[i].name, stu[i].no, stu[i].age);
30 };
31 main()
32 {
33     input();
34     output();
35     system("pause");
36 }
37     

 

转载于:https://www.cnblogs.com/anthozoan77/p/4063095.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Matlab优化算法是一种基于数学模型的计算方法,在许多领域中都有着广泛的应用。根据实际应用需求,我们可以选择适合的优化算法。下面罗列100个常见的Matlab优化算法: 1. 遗传算法(Genetic Algorithm) 2. 粒子群算法(Particle Swarm Optimization) 3. 差分进化算法(Differential Evolution) 4. 蚁群算法(Ant Colony Optimization) 5. 模拟退火算法(Simulated Annealing) 6. 人工鱼群算法(Artificial Fish Swarm Algorithm) 7. 历史遗传算法(Historical Genetic Algorithm) 8. 协方差矩阵适应进化策略(Convex Matrix Evolution Strategy) 9. 盲化梯度下降(Blind Gradient Descent) 10. 坐标下降法(Coordinate Descent) 11. 简单x方法(Simplex Method) 12. 对偶内点法(Dual Interior Point Method) 13. 增广拉格朗日法(Augmented Lagrangian Method) 14. 卡尔曼滤波(Kalman Filter) 15. 扩展卡尔曼滤波(Extended Kalman Filter) 16. 动态规划(Dynamic Programming) 17. 灰关联分析(Grey Relational Analysis) 18. 纯虚拟炼金术模拟算法(Purely Virtual Alchemy Simulation Algorithm) 19. 模糊控制算法(Fuzzy Control Algorithm) 20. 归纳逻辑程序设计算法(Inductive Logic Programming Algorithm) 21. Linear Programming 22. Nonlinear Programming 23. Quadratic Programming 24. Integer Programming 25. Semi-definite Programming 26. Combinatorial Optimization 27. Stochastic Programming 28. Convex Optimization 29. Non-negative Matrix Factorization 30. Support Vector Machine 31. Logistic Regression 32. Linear Discriminant Analysis 33. Naive Bayes Classifier 34. Principal Component Analysis 35. Independent Component Analysis 36. Karhunen-Loeve Transform 37. Wavelet Transform 38. Discrete Wavelet Transform 39. Fast Fourier Transform 40. Nonlinear Least Squares 41. Maximum Likelihood Estimation 42. Conditional Maximum Likelihood Estimation 43. Maximum A Posteriori Estimation 44. Sequential Monte Carlo 45. Markov Chain Monte Carlo 46. Gibbs Sampling 47. Metropolis-Hastings Algorithm 48. Hamiltonian Monte Carlo 49. Variational Bayes 50. Expectation-Maximization Algorithm 51. Structured Variational Bayes 52. Belief Propagation 53. Compressed Sensing 54. Sparse Representation 55. Non-negative Sparse Representation 56. Robust Principal Component Analysis 57. Low Rank Matrix Completion 58. Nonlinear Regression 59. Kernel Regression 60. Gaussian Process Regression 61. Kriging 62. Smoothing Splines 63. Nonparametric Regression 64. Discriminant Analysis 65. Nonparametric Bayes 66. Boosting 67. Random Forest 68. Deep Learning 69. Convolutional Neural Network 70. Recurrent Neural Network 71. Long Short-Term Memory 72. Autoencoder 73. Variational Autoencoder 74. Generative Adversarial Network 75. Reinforcement Learning 76. Q-Learning 77. Policy Gradient 78. Actor-Critic 79. Monte Carlo Tree Search 80. Exploration-Exploitation Dilemma 81. Batch Reinforcement Learning 82. Decision Trees 83. Naive Decision Trees 84. Randomized Decision Trees 85. Regression Trees 86. Tree Boosting 87. Gradient Boosting 88. Adaboost 89. Rank Boosting 90. Decision Forest 91. Learning to Rank 92. Unsupervised Learning 93. Clustering 94. K-Means 95. Gaussian Mixture Model 96. Hierarchical Clustering 97. Self-Organizing Maps 98. Non-negative Matrix Factorization Clustering 99. Subspace Clustering 100. Latent Dirichlet Allocation.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值