17.09.24周结
来源:互联网 发布:和平网络电视手机安卓 编辑:程序博客网 时间:2024/06/16 14:25
本周学到了什么
在本周的学习中,对递归有了一点基础的了解、学会了大数取余的方法、掌握了取幂的快速求法。
1、递归
递归是一种满足条件下对自身的重复调用。像汉诺塔、超级台阶、全排列等等问题都是使用递归解决的。
下面编写一段使用递归解决超级台阶的问题
#include<cstdio>#include<iostream>using namespace std;int nums = 0;void fun(int n){if(n == 0){nums++;return;}else if(n <0){return;}int temp=n;fun(temp-1);fun(temp-2);}int main(){int Nums[41];for(int i = 0; i < 41; i++){nums = 0;fun(i);Nums[i] = nums-1; }int T;scanf("%d",&T);while(T--){int num;scanf("%d",&num);printf("%d\n",Nums[num]);}return 0;}
2、大数取余
当要对一个数值大于long long范围的数进行取余时可以先将其用C-风格字符串进行存储,在通过逐步叠加的过程中不断取余便可以得到结果
具体实现如下
//求一个数对10003取余的结果; #include<iostream>#include<cstdio>#include<cstring> using namespace std;int main(){char temp[] = "123456789123456";int len = strlen(temp);int result = 0;for(int i = 0; i < len; i++){result = (result*10+temp[i]-'0')%10003; } cout << result << endl;return 0; }
3、快速取幂
要实现快速取幂,可以通过位运算进行求值。
具体实现如下
#include<iostream>#include<cstdio>using namespace std;long long POW(long long a, long long b, long long c){long long flag = a%c, result = 1;while(b != 0){if(b & 1){result = (result*flag)%c;}b = b >> 1;flag = (flag*flag)%c;}return result;}int main(){int T;cin >> T;long long a, b, c;while(T--){cin >> a >> b >> c;printf("%lld\n",POW(a, b, c));}return 0; }
下周要学什么
下周准备争取时间将递归吃透,并在南阳理工OJ上AC20道题。
阅读全文
0 0
- 17.09.24周结
- 英语快照总结-17.09.24
- 周结
- 17.09.24 牛客网练习总结:二维数组中的查找,替换空格
- 17.09.06
- unity3D__周结
- 2017年3月24日,周结(五),学生信息管理系统继续改进以及一些框架的使用
- 17.09.05日报
- 练习(17.09.06)
- 0717-0721周结
- 游百望山(记于17.09.05)
- 练习题2(17.09.06)
- Python学习笔记-17.09.08
- Python学习笔记-17.09.10
- Python学习笔记-17.09.13
- Python学习笔记-17.09.15
- 练习题4(17.09.16)
- 17.09.18 关于减脂
- Springboot+mybatis 搭建并完美整合
- Redis学习01——介绍与搭建环境
- 多线程的一些常见问题
- LeetCode:461 Hamming Distance
- 无穷小放飞互联网是我国之首创
- 17.09.24周结
- 神经网络与深度学习(四)- Deep Neural Network
- 简明 Python 教程
- LeetCode:657. Judge Route Circle
- Service知识点
- 搭建你的Spring.Net+Nhibernate+Asp.Net Mvc 框架 (一)
- 个非常好用的框架-AngularJS(一)
- Where is the best place to store a password in your Android app
- Prime Time UVA