HDU 1060 Leftmost Digit【对数运算】
来源:互联网 发布:剑网3菊花插件数据 编辑:程序博客网 时间:2024/05/14 07:33
题意:输出N^N最左边的一位数
假设给出一个数10234432【答案是5】,那么log10(10234432)=log10(1.0234432*10^7)=log10(1.0234432)+7;【7代表了末尾的0】
log10(1.0234432)就是log10(10234432)的小数部分.
log10(1.0234432)=0.010063744
10^0.010063744=1.023443198【不考虑小数点的话是这个数的前几位数据】
那么要取几位就很明显了吧~
先取对数(对10取),然后得到结果的小数部分bit,结果为pow(10.0,bit)的整数部位
若要取前n位,则是pow(10.0,bit+n),理由:
结合上面的例子你就知道这样能调整小数点位置,等会取整就是对的了
简之:已知大数n,求n^n的首位数,设x=n*log10 n,取x的小数部分b,再10的b次方,最后取整得出最高位。
floor(x)取不大于x的最大正整数,似乎可以用(int)替代,用(int)有时会出问题
鄙视下题目描述,”The input contains several test cases. "骗人的,然后杭电的C++代码检测好厉害,pow,log10函数里用int的就编译错误,还是乖乖加个.0变double吧
#include<math.h>#include<stdio.h>int main(){double n;double x;int t,ans;scanf("%d",&t); while(t--) { scanf("%lf",&n); x = n * log10(n) - (floor) ( n*log10(n) ) ; ans = (int) pow ( 10.0, x ); printf( "%d\n" , ans ) ; }return 0;}
0 0
- HDU 1060 Leftmost Digit【对数运算】
- HDU - 1060 Leftmost Digit (数学取对数)规律
- HDU 1060 Leftmost Digit & BIT1046 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 LeftMost Digit
- HDU 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- hdu - 1060 - Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- HDU 1060 Leftmost Digit
- html常用标签3
- 去除nag窗口
- Android 自动补全的文本框
- UVa 465 Overflow
- 理清文件编码,告别中文乱码
- HDU 1060 Leftmost Digit【对数运算】
- UNIX环境高级编程复习——文件和目录(1)
- Oracle 11g 学习四:多表查询、左右连接、SQL1999语法、统计函数及分组查询
- leetcode Best Time to Buy and Sell Stock(I~III)(*)
- iOS页面跳转及数据传递
- poj 3252(详解)
- 没有窗口怎么解决SetTimer问题
- 拓扑排序
- HDU 4920 Matrix multiplication 解题报告(暴力)