杭电ACM1060——Leftmost Digit
来源:互联网 发布:vb和微信公众号对接 编辑:程序博客网 时间:2024/06/05 13:31
这一题,主要是数学方面的知识,将ans = n^n进行化简。
两边取log。得到log(ans)= n * log(n);
再推出ans = 10 ^ (n * log (n));10的整数幂,只会在ans后面加上一个0,小数的幂才会影响ans的其他有效数字。
所以求出n * log(n)的小数部分temp,然后(int)10^temp就是所要求的结果。
数学,很重要!!~·
下面的是AC的代码,用C++提交,G++会CE:
#include <iostream>#include <cmath>using namespace std;int main(){int n, t;while(cin >> t){while(t--){cin >> n;double temp1 = n * log10(double(n));__int64 temp2 = __int64(temp1);double temp = temp1 - temp2;int a = (int)pow(10.0, temp);cout << a << endl;}}return 0;}
1 0
- 杭电ACM1060——Leftmost Digit
- 杭电ACM1060 Leftmost Digit
- 杭电 Leftmost Digit
- 杭电1060 Leftmost Digit
- 【杭电】[1060]Leftmost Digit
- 1060—Leftmost Digit
- 杭电OJ 1060 :Leftmost Digit
- 杭电acm hdu-1060Leftmost Digit
- 杭电 HDU 1060 Leftmost Digit
- 杭电 Leftmost Digit 题解 & 新发现
- 数学——Leftmost Digit
- 【杭电oj】1060 - Leftmost Digit(数学好题)
- hdu 1060——Leftmost Digit
- Leftmost Digit(杭电1060)(求N^N的最高位)
- 【杭电-oj】 -1060-Leftmost Digit(输出n的n次方最左边数)
- Leftmost Digit
- Leftmost Digit
- Leftmost Digit
- LeetCode--Find Minimum in Rotated Sorted Array
- VIM ctags, taglist
- Centos启动和禁用网卡命令
- Java获取当前时间的年月日方法
- PHP对象类型在内存中的分配
- 杭电ACM1060——Leftmost Digit
- Mybatis学习笔记-核心配置文件概述
- Linux系统下UDP发送和接收广播消息小例子
- python学习笔记(3)字符串
- Segmentation of PolSAR
- Android中ListView的Selector的用法
- 安卓开发环境的搭建
- Unity destructor Or OnDestory
- 通过网页去实现远程控制软件的上线!博客,贴吧,云盘等等网页方式实现上线原理解析,绕过域名拦截