HDU 1060 Leftmost Digit
基本思路:(参考大神和加自己的思考)
考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位。当时考虑用大数方法求(数组实现),结果实现不行。看网上大神采用对数法,巧妙避开处理这么大的数。 这就是数学的魅力!!
假如aa=b,两边同时取对数alog10a=log10b,从而有b=10alog10a.现在我们关注点在10alog10a,先举例:一个数2310,这个数,换成10c次幂,这里的c=3.xxxxx.如果把他取整一定为3,103是最大的权值,那剩下的100.xxxxx取整之后就是所求的最高位的基。
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n;
cin>>n;
__int64 d,b;//int型不行
double a,c;
while(n--)
{
unsigned long m;
cin>>m;
a=m*log10(m*1.0);//alog10a
b=(__int64)a;//取整
c=a-b;//0.xxxxx
d=(__int64)pow(10.0,c);//10^0.xxxxx 取整
cout<<d<<endl;
}
return ;
}
下面介绍一下__int64:
在C/C++中,64为整型一直是一种没有确定规范的数据类型。现今主流的编译器中,对64为整型的支持也是标准不一,形态各异。一般来说,64位整型的定义方式有long long和__int64两种(VC还支持_int64),而输出到标准输出方式有printf("%lld",a),printf("%I64d",a),和cout << a三种方式。
还有几点:
- long long定义方式可以用于gcc/g++,不受平台限制,但不能用于VC6.0。
- __int64是Win32平台编译器64位长整型的定义方式,不能用于Linux。
- "%lld"用于Linux i386平台编译器,"%I64d"用于Win32平台编译器。
- cout只能用于C++编译,在VC6.0中,cout不支持64位长整型。
详细请见:https://www.byvoid.com/blog/c-int64/
HDU 1060 Leftmost Digit的更多相关文章
- HDU 1060 Left-most Digit
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- HDU 1060 Leftmost Digit
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit (数论,快速幂)
Given a positive integer N, you should output the leftmost digit of N^N. InputThe input contains se ...
- HDU 1060 Leftmost Digit【log10/求N^N的最高位数字是多少】
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- HDU 1060 Leftmost Digit (数学/大数)
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- 题解报告:hdu 1060 Leftmost Digit
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 问题描述 给定一个正整数N,你应该输出N ^ N的最左边的数字. 输入 输入包含多个测试用例. ...
- HDU 1060 Leftmost Digit 基础数论
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10 ...
- HDU 1060 Leftmost Digit (数学log)
题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以 ...
随机推荐
- cache与SDRAM
hugohong hugohong 本版等级: #2 得分:20回复于: 2009-04-19 21:51:03 牛人说的,拿出来分享一下:cache是高速缓冲, 解决高速cpu和相对低速sdra ...
- SQL 过滤 having
select * from emp --having 对分组之后使用 --输出部门号 和 部门的平均工资 并且 平均工资 > 2000 select deptno, avg(sal) as &q ...
- linux环境变量与本地变量
两者不同的是. 环境变量可以在shell的子进程中使用, 而本地变量不同. 每当连接上服务器时,服务器就会通过帐号密码运行一个SHELL,我们所做的工作都在这个SHELL上,特殊方法除外(如,守护进程 ...
- hdu5322 Hope
设dp[n]为n个数字排列时候的答案,那么可以得到dp方程 dp[n]=Σdp[n-i]*c(n-1,i-1)*(i-1)!*i^2(1<=i<=n) 然后上式可以化成卷积形式,分治FFT ...
- android中获取打气筒的几种方式
1,简单说明,打气筒就是将我们的xml布局转换为我们的view对象,不扯远了,直接看代码 A:从context中获取 LayoutInflater inflater1 = LayoutInflater ...
- sql 把一列的数据按逗号分隔转换成多行
ALTER proc [dbo].[ModifyWkCashAccountNo]asbeginset xact_abort onbegin transactiondeclare @errors int ...
- DataTable 筛选数据
//使用聚合函数 max ,sum ,count .... private void ComputeBySalesSalesID(DataSet dataSet) { // Presumes ...
- JSP-06-使用JDBC操作数据库
6.1 使用JDBC查询数据 [链接oracle数据库] 具体操作: 1) 将odbc文件拷贝到项目中 Odbc文件所在目录: oracle安装目录下- product – db_1 – jdbc ...
- Inside TSQL Querying - Chapter 3. Query Tuning
Tuning Methodology When dealing with performance problems, database professionals tend to focus on t ...
- c#中 ==与equals有什么区别【转】
转至http://www.zybang.com/question/2263895f201ffec6c68b6c304ac4cd61.html 对于值类型.引用类型来说比较过程怎样的?using Sys ...