HDU 1060 Leftmost Digit (数学/大数)】的更多相关文章

Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 14954    Accepted Submission(s): 5775 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
Given a positive integer N, you should output the leftmost digit of N^N.  InputThe input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test case contains a…
传送门 Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15305    Accepted Submission(s): 5937 Problem Description Given a positive integer N, you should output the leftmost digit of N…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 21744    Accepted Submission(s): 8408 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20361    Accepted Submission(s): 7864 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19010    Accepted Submission(s): 7507 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以10为底对数 lg(ans) = n * lg(10),然后这个整数部分都是10的多次方, 没什么用,也就是说我们要的小数部分,然后再取指数,就OK了.还要注意要用long long因为可能超int了,第一次忘了,WA了. 代码如下: #include <iostream> #include &l…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060   这道题运用的是数学方法. 假设S=n^n.两边同时取对数,得到lgS=nlgn.即有S=10^(nlgn). 把nlgn看做一个整体,假设它是由整数加上介于0到1之间的小数相加得到的. 那么整数部分就不考虑了,就单纯的放大倍数而已.取决于小数部分. 小数部分=nlgn-(__int64)nlgn.注意是__int64.因为小数部分在0到1之间,所以10得次方得到的数必定大于等于1且小于10…
题目链接: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 =…
基本思路:(参考大神和加自己的思考) 考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位.当时考虑用大数方法求(数组实现),结果实现不行.看网上大神采用对数法,巧妙避开处理这么大的数. 这就是数学的魅力!! 假如aa=b,两边同时取对数alog10a=log10b,从而有b=10alog10a.现在我们关注点在10alog10a,先举例:一个数2310,这个数,换成10c次幂,这里的c=3.xxxxx.如果把他取整一定为3,103是最大的权值,那剩下的100.xxxxx取整之后…
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * 10^x;其中x也是未知的: 两边取log10有:lg(n^n) = lg(a * 10^x); 即:n * lg(n)  - x = lg(a); 现在就剩x一个变量了,我们知道x是值n^n的位数-1,a向下取整就是我们要求的数: 所以 按着上面的推导式翻译成代码就可以了(注意:数值的范围和之间的…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1982 Accepted Submission(s): 884 Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input T…
Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each test ca…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12229    Accepted Submission(s): 4674题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1060 Problem Description Given a positive integ…
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围,即使是long long也无法存储. 因此需要利用 (a*b)%c = (a%c)*(b%c)%c,一直乘下去,即 (a^n)%c = ((a%c)^n)%c; 即每次都对结果取模一次 此外,此题直接使用朴素的O(n)算法会超时,因此需要优化时间复杂度: 一是利用分治法的思想,先算出t = a^(n/2),若…
Problem Description Given a positive integer N, you should output the leftmost digit of N^N.   Input The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow. Each…
Leftmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 16762    Accepted Submission(s): 6643 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
find the nth digit Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7403    Accepted Submission(s): 2120 Problem Description 假设:S1 = 1S2 = 12S3 = 123S4 = 1234.........S9 = 123456789S10 = 12345678…
Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequence consisting of one digit, the number 1 is initially written into a computer. At each successive time step, the computer simultaneously tranforms each…
pid=4873" target="_blank" style="">题目链接:hdu 4873 ZCC Loves Intersection 题目大意:给出N,D,表示在一个D维的坐标上.坐标范围为0~N-1.在这个坐标系中有D条线段,分别平行与各个坐标轴,每秒会依据题目中的伪代码随机生成各个线段的位置.两条直线相交的话会得一分,问每秒得分的期望. 解题思路:总的情况(ND−1∗C(2N))D,两条直线相交的得分C(2D)∗s2∗ND−2∗(ND−…
Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26383    Accepted Submission(s): 12006 Problem Description In many applications very large integers numbers are required. Some of thes…
  HDU1002   A + B Problem II [题意]大数相加 [链接]http://acm.hdu.edu.cn/showproblem.php?pid=1002 Sample Input 2 1 2 112233445566778899 998877665544332211   Sample Output Case 1: 1 + 2 = 3 Case 2: 112233445566778899 + 998877665544332211 = 1111111111111111110…
本题假设编程是使用DP思想直接打表就能够了. 假设是找规律就须要数学思维了. 规律就是看这些连续的0是从哪里来的. 我找到的规律是:1经过两次裂变之后就会产生一个00: 00经过两次裂变之后也会产生新的00:故此须要记录好1和00出现的次数就能够递推出后面的00出现的数据了. 公式就是tbl00[i] = tbl00[i-2] + tbl1[i-2]; 当中tbl00是记录00出现的次数,tbl1是出现1出现的次数. 公式事实上是能够化简的,只是我懒得化简了.这种公式非常清楚了. 只是因为这种数…
原题代号:HDU 1314 原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1314 Numerically Speaking Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 766    Accepted Submission(s): 190 Problem Description A de…
题目是说给出一个数字,然后以1到这个数为序号当做二叉树的结点,问总共有几种组成二叉树的方式.这个题就是用卡特兰数算出个数,然后因为有编号,不同的编号对应不同的方式,所以结果是卡特兰数乘这个数的阶乘种方案.因为数字比较大,所以要用高精度的方法也就是用字符数组来做,我分别写了三个函数,一个算加法,一个算乘法,最后一个打表,等打出表来最后只要判断一下输入的数是第几个,直接输出就行了,下面是我的代码,第一次写高精度的这种大数处理,可能看上去比较繁琐= = #include<iostream> #inc…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4816 Problem Description The Bathysphere is a spherical deep-sea submersible which was unpowered and lowered into the ocean on a cable, and was used to conduct a series of dives under the sea. The Bathys…
解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #include<iostream> #include<cmath> using namespace std; int PowerMod(__int64 a,__int64 b,int c)//快速幂取余 { ; a=a%c; ) { ==)//如果为奇数时,要多求一步,可以提前放到ans中…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5568 题意: 求所有长度为k的严格升序子序列的个数. 题解: 令dp[i][k]表示以i结尾的长度为k的所有严格升序子序列的个数,则有状态转移:dp[i][k]+=dp[j][k-1](其中,arr[i]>arr[j],并且i>j): 最后答案为dp[1][k]+...dp[n][k]. 代码: import java.util.*; import java.math.*; public cla…
LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 Description A frog has just learned some number theory, and can't wait to show his ability to his girlfriend. Now the frog is sitting on a grid map o…
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include &…