HDU 1060 Leftmost Digit
来源:互联网 发布:.net是编程语言吗 编辑:程序博客网 时间:2024/05/30 05:28
【链接】:click here~~
【题意】:求n^n得到的数的最左边的数
【思路】
开始看到此题首先想到的是位运算,记得有一个向右取第k 位数的技巧: num >> (num_length-1) & 1,则还需要知道数的位数,可以转换成字符串来处理
另外一种巧妙的方法:
需要用到科学记数法和对数运算的知识:把num^num的值记作:num^num=a*10^n,比如三位数abc= a.bc*10^2,那么(1<a<10);
然后通过两边取对数的方法得到num*log10(1.0*num)=log10(a)+n,这时0<log10(a)<1;令x=n+log10(a),得到log10(a)=x-n;所以a=10^(x-n);n为整数部分,log10(a)为小数部分,由x=n+log10(a),可知(int)x=n;最终a=10^(x-n)=10^(x-(int)x)
<span style="font-family:SimSun;font-size:14px;">#include <queue>#include <deque>#include <vector>#include <stack>#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <iostream>#include <algorithm>using namespace std;int main(){ // freopen("1.txt","r",stdin); int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); double m; if(n==1){puts("1");continue;} m=n*log10((double)n); m-=(long long)m; printf("%d\n",(int)pow(10,m)); } return 0;}</span>
0 0
- 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
- HDU-1060 Leftmost Digit
- hdu 1060 Leftmost Digit
- 编译语言和解释语言(脚本)
- PPAPI插件与浏览器的通信
- VC C++ 操作 Excel 总结
- converting to execution character set: Invalid or incomplete multibyte or wide character
- PhoneWindow对象的创建
- HDU 1060 Leftmost Digit
- iOS 网络请求数据两种请求方式GET,POST
- Java常见关键字
- ListView 中设置setonitemclicklistener()监听时,无法获取item条目的点击事件焦点
- PHP学习之数组
- 我的Android进阶之旅------>Android Activity的singleTask加载模式和onActivityResult方法之间的冲突
- Python---索引
- 2016年1月13日
- HiveSql(3)HiveSQL与oracle SQL的区别