HDU 1061 EASY】的更多相关文章

//回宿舍去了,明天做点难一点的题,今天做的都很水,感觉.没意思.#include <iostream> #include <cstdio> using namespace std; const __int64 MOD=10; __int64 Power(__int64 a,__int64 b,__int64 m){ a%=m; __int64 ans=1; while(b){ if(b&1){ ans=(ans*a)%MOD; } b=b>>1; a=(a*a…
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),若…
题目意思: http://acm.hdu.edu.cn/showproblem.php?pid=1061 求N^N的最后一位数. 题目分析: 此题有非常多种方法,主要是中循环节,看自己怎么找了.我的方法是找到全部个位数(0-9)数的循环节,详见代码. AC代码: /** *全部数的循环节是12 */ #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> using na…
别easy在一系列的 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 101   Accepted Submission(s) : 38 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description 大家经常感慨,要做好一件事情真的不easy,确实,…
So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2026    Accepted Submission(s): 624 Problem Description A sequence Sn is defined as:Where a, b, n, m are positive integers.┌x┐is the ceil…
An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 3845    Accepted Submission(s): 768 Problem Description On an infinite smooth table, there's a big round fixed cylinder an…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1460    Accepted Submission(s): 557 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
So Easy! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4316    Accepted Submission(s): 1402 Problem Description A sequence Sn is defined as: Where a, b, n, m are positive integers.┌x┐is the c…
id=17433" target="_blank" style="color:blue; text-decoration:none">An easy problem Time Limit: 3000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status Description When Teddy was a child , he was always…
An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first…
Easy Tree DP? Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 567 Problem Description A Bear tree is a binary tree with such properties : each node has a value o…
Easy Sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 766    Accepted Submission(s): 208 Problem Descriptionsoda has a string containing only two characters -- '(' and ')'. For every c…
求n^n的个位 Sample Input 2 3 4 Sample Output 7 6 直接快速幂了,注意要用long long #include<cstdio> long long quick_mod(long long a,long long b,long long m) { ; while (b) { ) { ans = (ans * a) % m; b--; } b/=; a = a * a% m; } return ans; } int main() { int t,n; scan…
解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考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中…
#include<stdio.h> #include<string.h> int a[10]; int main() { int T,n,i,k,temp,b,t; scanf("%d",&T); while(T--) { memset(a,0,sizeof(a)); scanf("%d",&n); t = n; n %= 10; if(n==1||n==0) { printf("%d\n",n); con…
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板,写法简洁. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define clc(a,b) sizeof(a,b,sizeof(a)) #define LL l…
求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h> int rightMost(int n, int N) { if (n == 0) return 1; int t = rightMost(n / 2, N); t = t * t % 10;; if (n % 2) t *= N; return t % 10; } int main() { int T…
题意: 给定n deep 1.构造一个n个节点的带权树,且最大深度为deep,每一个节点最多仅仅能有2个儿子 2.每一个节点的值为2^0, 2^1 ··· 2^(n-1)  随意两个节点值不能同样 3.对于一个节点,若他有左右儿子,则左子树的和 < 右子树的和 问: 有多少种构造方法. 思路: dp #include <stdio.h> #include <iostream> #include <algorithm> #include <cstring>…
题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map> using…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 55522    Accepted Submission(s): 20987 Problem Description Given a positive integer N, you should output the most right digit of N…
Problem 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…
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,M=9973; struct Matrax { int m[15][15]; }; Matrax a,per; void initial(){ int i,j; for(i=0;i<n;i++){ for(j=0;j<n;j++){ sca…
#include <iostream> #include <cstdio> using namespace std; const __int64 MOD=200907; __int64 Power(__int64 a,__int64 b,__int64 m){ a%=m; __int64 ans=1; while(b){ if(b&1){ ans=(ans*a)%MOD; } b=b>>1; a=(a*a)%MOD; } return ans; } int ma…
链接:传送门 题意:求 N^N 的个位 思路:快速幂水题 /************************************************************************* > File Name: hdu1061.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年05月17日 星期三 22时50分05秒 **************…
题意:定义一种树,每个节点的权值都是20到2n-1,每个权值出现一次,每个节点的左子树的权值和小于右子树,除非只有一个子树.给你n和d,问有n个节点且恰好深度是d的这种树有多少种. 比赛的时候我没有做出来,当时A的人还是不少,\ 有一个超傻逼的居然没想到,就是  ,这表示一个权值较大的节点是大于所有权值小于他的值之和的. 所以对于每一个合法的树,只要把权值最大的放到右子树就可以满足了. 动归过程:f[i][j]表示i个节点深度不超过j的方案种数. ; i <= N; i++){ ; j <=…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57430    Accepted Submission(s): 21736 Problem Description Given a positive integer N, you should output the most right digit of N…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 求: \[\sum_{i=1}^{n}\sum_{j=1}^{n}gcd^k(i, j)\times lcm(i, j)\times [gcd(i, j) \in prime] \mod 10^9 + 7 \] 原题传送门. @solution@ \[\begin{aligned} ans &= \sum_{i=1}^{n}\sum_{j=1}^{n}gcd^k…
HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsum  贪心 HDU 1004 Let the Balloon Rise  字典树,map HDU 1005 Number Sequence  求数列循环节 HDU 1007 Quoit Design  最近点对 HDU 1008 Elevator  模拟 HDU 1010 Tempter of th…
快速幂百度百科:快速幂就是快速算底数的n次幂.其时间复杂度为 O(log₂N), 与朴素的O(N)相比效率有了极大的提高. HDU - 1061 代码实现如下: import java.util.Scanner; public class Main { public static void main(String []args) { Scanner cin = new Scanner(System.in); int T = cin.nextInt(); for(int i = 0; i < T;…
C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1061 Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test case…