HDU1060 Leftmost Digit
来源:互联网 发布:jsp 收费系统 源码 编辑:程序博客网 时间:2024/05/01 18:31
题目大意:和1061看起来很相似,求n^n最左位上的数字。
显然n的取值是1--1,000,000,000,直接求简直是作死。
分析一下就会知道,对于一个数,求他最左位(即最大位)上的数字,只需把这个数用科学计数法表示成d.xxx *10^m即可。
那么对于本题,d.xxx*10^m=n^n,其中m是n^n的位数-1(m=(int)log(n^n))两边同时取对数得:log( d.xxx*10^m )=log(n^n),
化简得:log(d.xxx)=n*log(n)-(int)n*log(n);
然后同时取幂,d.xxx=10^(n*log(n)-(int)n*log(n));
d=(int)d.xxx即为最后结果。
不过需要注意的是本题n可以取到1,000,000,000,所以直接算n*log(n)肯定会超的,提交一看是WA,秒懂。
#include <cstdio>#include <iostream>#include <math.h>using namespace std;int main(){ int t; while(scanf("%d",&t)!=-1) while(t--) { int n; scanf("%d",&n); double ans=log10((double)n)-(int)log10((double)n); ans=n*ans-(int)(n*ans);//直接用n*log10(n)会超出double范围,提交结果是WA。 printf("%d\n",(int)(pow(10.0,ans))); } return 0;}
0 0
- hdu1060 Leftmost Digit(转载)
- hdu1060-Leftmost Digit
- HDU1060--Leftmost Digit
- HDU1060 Leftmost Digit 【数学】
- Leftmost Digit hdu1060
- HDU1060 Leftmost Digit
- hdu1060 Leftmost Digit
- hdu1060 Leftmost Digit
- HDU1060 Leftmost Digit
- HDU1060 Leftmost Digit
- hdu1060 Leftmost Digit
- HDU1060 Leftmost Digit
- HDU1060 Leftmost Digit (数学推导)
- HDU1060:Leftmost Digit(数论)
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- Array(数组)与Json String (Json字符串) 的相互转换
- 打造自己的js库1 -- 脚本动态加载
- 精读《JAVAScript高级程序设计》笔记(一)——基本概念
- exact nn search in hamming space
- JSChart_页面图形报表
- HDU1060 Leftmost Digit
- sizeof
- values-sw600dp 平板电脑中无效【安卓调试】
- LeetCode 17 4Sum
- 设计模式学习笔记-观察者模式
- J2SE学习
- ServletContext
- Android 中的 Service 全面总结
- 页面传值乱码问题