A: HDU5170
这题让比较a^b与c^d的大小。1<=a,b,c,d<=1000.
显然这题没法直接做,要利用对数来求,但是在math库中有关的对数函数返回的都是浮点数,所以这又要涉及到eps问题。
其它就没有什么需要注意的了,我用的是log()函数,当然还可以用log10().....,原理不变。
B: HDU5171
题目:按照规则扩展一个集合k次,然后求其总和。
【分析】
扩展规则很简单,就是一个斐波那契数列,但是如果按照模拟的方法手动推算,复杂度对于本题的数据范围来说是不太合适的。(1≤k≤1000000000)
可以利用矩阵快速幂来迅速完成。(矩阵快速幂可以完成任何递推公式)
[0, 1, 0]
[f[n-1],f[n],s[n-1]]*[1, 1, 1] = [f[n],f[n+1],s[n]]
[0, 0, 1]
我第一次写完代码后验证结果是对的,但提交一直WA,之后发现在计算矩阵A的k+1次幂时,发现中间爆数据了,果断把int a[3][3]改成了 __int64 a[3][3],果断A了。