DayThirteen 笔记

使用sort函数时,可以传入第三个参数,作为排序的顺序参考,例如:

bool cmp(pair<double, double> a, pair<double, double> b)
{
	return a.second > b.second;//从大到小排序
}

int main(){
	sort(danjia, danjia + n, cmp);
}

记录一个求幂函数的二分算法

LL bineryPow(LL a, LL b, LL m)//递归写法
{
	if (b == 0)return 1;//如果幂为0,啧直接返回
	//这里b&1相当于b%2 == 1,通过位操作,节省时间
	if (b & 1)return a * bineryPow(a, b - 1, m) % m;//这里如果是奇数,则先递归求的低一级幂
	else {//偶数啧求一般幂
		LL mul = bineryPow(a, b / 2, m);
		return mul * mul% m;
	}
}

LL binaryPow(LL a, LL b, LL m)//迭代写法
{
	LL ans = 1;
	while (b > 0)
	{
		if (b & 1)ans = ans * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return ans;
}
bb&1ansa
1a
110111 * a = aa2
1100aa4
110a * a4 = a5a8
11a5 * a8 = a13

每天敲一遍归并的代码,感觉自己萌萌哒

const int maxn = 100010;
void merge(int A[], int L1, int R1, int L2, int R2)
{
	int i = L1, j = L2;
	int temp[maxn], index = 0;
	while (i <= R1, j <= R2)
	{
		if (A[i] <= A[j])temp[index++] = A[i++];
		else temp[index++] = A[j++];
	}
	while (i <= R1)temp[index++] = A[i++];
	while (j <= R2)temp[index++] = A[j++];
	for (int i = 0; i < index; i++) A[L1 + i] = temp[i];
}

顺带回忆一下归并排序的思路,读入数组和左右边界,只要还在范围内,先递归的处理左边和右边,处理到只有一个元素的时候,进行归并。

记得练习Pair和Map的使用,还有vector、双指针的使用。

在做链表的题的时候,可以先新建一个node指向原链表,作为一个虚拟的头节点,这样可以减少边界的判定。

%取余 /下取整

要有理想

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值