zoukankan      html  css  js  c++  java
  • 题解报告:hdu 1060 Leftmost Digit

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060

    问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字。  

    输入

      输入包含多个测试用例。 输入的第一行是单个整数T,它是测试用例的数量。 T测试用例如下。 每个测试用例都包含一个正整数N(1 <= N <= 1,000,000,000)。  

    输出

       对于每个测试用例,您应该输出N ^ N的最左边的数字。  

    示例输入

    2

    3

    4  

    示例输出

    2

    2

    暗示:在第一种情况下,3 * 3 * 3 = 27,所以最左边的数字是2。 在第二种情况下,4 * 4 * 4 * 4 = 256,所以最左边的数字是2。

    解题思路:这道题只跟ACM_Leftmost Digit里面的N的范围有差别,HDU这里给的N最大为10^9,即x=N*lg(N)=9*10^9(10位数)爆int范围,所以只需将x强转long long即为m整数部分,其他代码没变。

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main()
     4 {
     5     int T,N;
     6     while(cin>>T){
     7         while(T--){
     8             cin>>N;
     9             double x=N*log10(N);
    10             double g=x-(long long)x;
    11             cout<<(int)pow(10,g)<<endl;
    12         }
    13     }
    14     return 0;
    15 }
  • 相关阅读:
    批处理系列(10)
    批处理系列(11)
    批处理系列(9)
    批处理系列(7)
    批处理系列(8)
    批处理系列(6)
    批处理系列(4)
    批处理系列(5)
    Java项目性能监控和调优工具-Javamelody的学习总结
    easyUI 接收Spring Mvc中@ResponseBody中文乱码解决
  • 原文地址:https://www.cnblogs.com/acgoto/p/8886017.html
Copyright © 2011-2022 走看看