hdu 1060 Leftmost Digit

  一句话题意:让你求n^n的最左位的数字是多少。

  题解:n最大可以为1000000000,那n^n就是超大的数了,,对于求关于n次方、斐波那契额和阶乘的位数这类的问题,首先就会想到取对数什么的(套路...);那么,看这题,对于m=n^n,有log10(m)=n*log10(n); 假设log10(m)=X.abcd,n^n=H.efgh*10^y;那么,又因为10^X.abcd=m=H.efgh*10^y; 则必有:X=H;故:10^0.abcd=H.efgh;求出10^0.abcd后,那它的整数位就是n^n的最左位了。  (另外,在对double取整时用(int)强转时会一直莫名的wa...估计应该是double为64位、int为32位互相转换损失的精度在某些数据上会给坑。。。)

ac代码:

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <cmath>
 6 #include <set>
 7 #include <utility>
 8 #include <vector>
 9 #include <map>
10 #include <queue>
11 #include <stack>
12 const int inf=0x3f3f3f3f;
13 const double PI=acos(-1.0);
14 const double EPS=1e-8;
15 using namespace std;
16 typedef long long ll;
17 typedef pair<int,int> P;
18 
19 void debug()
20 {
21 }
22 int n;
23 int main()
24 {
25     //freopen("input.txt","r",stdin);
26     //debug();
27     int T;
28     scanf("%d",&T);
29     while(T--)
30     {
31         scanf("%d",&n);
32         double temp=(double)n*log10((double)n);
33         //temp-=(int)temp;
34         temp-=(ll)temp;   //
35         double tt=pow(10.0,temp);
36         int ans=(int)tt;
37         cout<<ans<<endl;
38     }
39     return 0;
40 }
原文地址:https://www.cnblogs.com/geek1116/p/6608071.html