算法学习
菜鸡弟弟学习算法
嘻嘻哈哈Man
这个作者很懒,什么都没留下…
展开
-
BFS二叉树层序遍历
class Solution { public int[] levelOrder(TreeNode root) { //排除特殊情况 if(root==null) return new int[0]; //队列保存状态 Queue<TreeNode> queue=new LinkedList<TreeNode>(); List<.原创 2022-01-04 22:14:06 · 164 阅读 · 0 评论 -
c++运算符重载
为什么要重载运算符?如果不做特殊处理,C++ 的 +、-、*、/ 等运算符只能用于对基本类型的常量或变量进行运算,不能用于对象之间的运算。有时希望对象之间也能用这些运算符进行运算,以达到使程序更简洁、易懂的目的。例如,复数是可以进行四则运算的,两个复数对象相加如果能直接用+运算符完成,不是很直观和简洁吗?利用 C++ 提供的“运算符重载”机制,赋予运算符新的功能,就能解决用+将两个复数对象相...原创 2020-01-13 09:34:18 · 218 阅读 · 0 评论 -
拓扑排序
题目The system of Martians’ blood relations is confusing enough. Actually, Martians bud when they want and where they want. They gather together in different groups, so that a Martian can have one pare...原创 2020-01-11 10:33:31 · 105 阅读 · 0 评论 -
算法时间复杂度表
C++代码中的操作次数控制在10的7次方左右最好。原创 2019-12-12 19:59:06 · 233 阅读 · 0 评论 -
快速幂
**问题描述 **给定A, B, P,求(A^B) mod P。输入格式输入共一行。 第一行有三个数,A, B, P。输出格式输出共一行,表示所求。样例输入2 5 3样例输出2数据规模和约定A, B为64位范围内的非负整数,P为32位范围内的非 负整数#include<iostream>using namespace std;#define ll lo...原创 2019-10-24 19:41:14 · 74 阅读 · 0 评论 -
求a乘b对p取模的值。
题目描述:求a乘b对p取模的值。输入:第一行输入整数a,第二行输入整数b,第三行输入整数p。 0< a , b, p <= 10^18输出:输出一个整数,表示a*b mod p的值。样例输入:345样例输出:2#include<iostream>#include<cstdio>#include<algorithm>us...原创 2019-10-22 20:29:32 · 2272 阅读 · 0 评论