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.…
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): 14954    Accepted Submission(s): 5775 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
题目链接: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 =…
题目链接: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…
基本思路:(参考大神和加自己的思考) 考虑到此题需要输入这么大的数a,并且还的求aa,求出来会更大,更多位.当时考虑用大数方法求(数组实现),结果实现不行.看网上大神采用对数法,巧妙避开处理这么大的数. 这就是数学的魅力!! 假如aa=b,两边同时取对数alog10a=log10b,从而有b=10alog10a.现在我们关注点在10alog10a,先举例:一个数2310,这个数,换成10c次幂,这里的c=3.xxxxx.如果把他取整一定为3,103是最大的权值,那剩下的100.xxxxx取整之后…
题意:给定一个数n,让你求出n的n次方的第一位数. 析:一看这个n快到int极限了,很明显不能直接做,要转化一下.由于这是指数,我们可以把指数拿下来. 也就是取对数,设ans = n ^ n,两边取以10为底对数 lg(ans) = n * lg(10),然后这个整数部分都是10的多次方, 没什么用,也就是说我们要的小数部分,然后再取指数,就OK了.还要注意要用long long因为可能超int了,第一次忘了,WA了. 代码如下: #include <iostream> #include &l…
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…
Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description 2007年到来了.经过2006年一年的修炼,数学神童zouyu终于把0到100000000的Fibonacci数列 (f[0]=0,f[1]=1;f[i] = f[i-1]+f[i-2](i>=2))的值全部给背了下来. 接下来,CodeStar决定要考考他,于是每问他一…
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…
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…
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): 16762    Accepted Submission(s): 6643 Problem Description Given a positive integer N, you should output the leftmost digit of N^N.…
Description Given a positive integer N, you should output the most right 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…
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want you…
Description Given a positive integer N, you should output the most right 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…
#include<stdio.h> #include<math.h> int main() { int A,k,B,sum,c,d; while(scanf("%d%d%d",&A,&B,&k)&&(A||B)) { if(A%(c=pow(10.0,k))==B%(d=pow(10.0,k))) { sum=-; } else { sum=A+B; } printf("%d\n",sum); } }…
题目: 给出1个正整数,找到用与这个数字相同的digit组成的整数中比这个数字大的数集中的最小数字.比如:12352874 的结果是 12354278 分析: 这道题目的考虑目标是数组的查找与排序. 当然, 前提是你得明白这道题目的思路是什么样子的. 把正整数转化为char数组a, 长度为n, 末尾字符是a[n-1], 然后对该数组逆序查找, 会发现, 第一个a[n-1]比小的字符是a[i], 然后字符a[i]跟a[n-1]交换, 最后对数组中i到n-1的部分进行升级排序, 你会发现, 正是最后…
/** 题目:E - Leading and Trailing 链接:https://vjudge.net/contest/154246#problem/E 题意:求n^k得前三位数字以及后三位数字,保证一定至少存在六位. 思路:后三位求法只要不断对1000取余就行了. 前三位求法: 对一个数x,他可以用科学计数法表示为10^r*a (r为次方,1<=a<10) 设:n^k = x = 10^r*a 两边取对数: k*log10(n) = log10(x) = r+log10(a); 令y =…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4607 题目大意:给你n个点,n-1条边,将图连成一棵生成树,问你从任意点为起点,走k(k<=n)个点,至少需要走多少距离(每条边的距离是1): 思路:树形dp求树的直径r: a:若k<=r+1 ,ans = k-1: b:若k>=r+1,ans = r+(k-(r+1))*2: 代码: #include "stdio.h" #include "string.h&…
每次有n个盒子,每个盒子有容量上限,每次操作可以放入石头,数量为不超过当前盒子中数量的平方,不能操作者输. 一个盒子算一个子游戏. 对于一个盒子其容量为s,当前石子数为x,那么如果有a满足 $a \times a + a < s     \land   (a+1) + (a+1)^2 >= s$,那么可知此时的sg(s,a)为0,为终止态,如果此时x > a,那么直接结束了,后继局面数为s-x,而如果x<=a,则以此时的a作为下一终止的目标,递归求sg值. 最后SG和就好了. /*…
http://acm.hdu.edu.cn/showproblem.php?pid=5017 求椭圆上离圆心最近的点的距离. 模拟退火和三分套三分都能解决 #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; const double eps = 1e-8; const double r = 0.99; //降温速度 co…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4311 解题报告:在一个平面上有 n 个点,求一个点到其它的 n 个点的距离之和最小是多少. 首先不得不说一下做这道题囧的事,杭电用的是__int64,我前面定义的时候用的是__int64,然后后面输出结果的时候格式控制符竟然用了%lld,还小卡了一会,唉,大意了啊. 然后感觉这题好巧妙,做法是将 x 与 y的距离分开求,我也是看了学长博客之后才懂的http://www.cnblogs.com/Lyu…
Cyclic Nacklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 14416    Accepted Submission(s): 6016 Problem Description CC always becomes very depressed at the end of this month, he has checke…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4291 思路:首先保留求出循环节,然后就是矩阵求幂了. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; typedef __int64 ll; #define MOD2 1000000007 #define MOD1 222…