zrq495
www.zrq495.com

随笔分类 -  HDU

上一页 1 2
HDU 2098 分拆素数和
摘要:1 #include<iostream> 2 #include<cmath> 3 4 using namespace std; 5 6 int prime(int n) 7 { 8 int i; 9 for (i=2; i<sqrt(n)+1; i++)10 {11 if (n%i == 0) return 0;12 }13 return 1;14 }15 16 int main()17 {18 int n, i;19 int cnt;20 while(cin >> n, n)21 {22 ... 阅读全文
posted @ 2012-07-31 14:54 zrq495 阅读(152) 评论(0) 推荐(0)
HDU 1905 Pseudoprime numbers
摘要:题意:给一个 p 和 一个 a,如果这个p 本身就是一个素数,就输出 no,如果不是素数,那么计算( a ^ p) % p 如果结果等于 a 那么输出 yes 否则输出 no。快速幂取模就是在O(logn)内求出a^n mod b的值。算法的原理是(a*b) mod c=(a mod c)*(b mod c)mod c。代码如下: 1 #include<iostream> 2 #include<cmath> 3 4 using namespace std; 5 6 int prime(long long n) 7 { 8 int i; 9 for (i=2; i< 阅读全文
posted @ 2012-07-31 14:51 zrq495 阅读(152) 评论(0) 推荐(0)
HDU 1465 不容易系列之一
摘要:错排: 当n个编号元素放在n个编号位置, 元素编号与位置编号各不对应的方法数用M(n)表示, 那么M(n-1)就表示n-1个编号元素放在n-1个编号位置, 各不对应的方法数, 其它类推. 第一步, 把第n个元素放在一个位置, 比如位置k,一共有n-1种方法; 第二步,放编号为k的元素,这时有两种情况. 1,把它放到位置n,那么,对于剩下的n-2个元素,就有M(n-2)种方法; 2,不把它放到位置n,这时,对于这n-2个元素,有M(n-1)种方法; 综上得到 M(n)=(n-1)[M(n-2)+M(n-1)] 特殊地,M(1)=0,M(2)=1最小的几个错排数是:D... 阅读全文
posted @ 2012-07-31 14:23 zrq495 阅读(166) 评论(0) 推荐(0)
HDU 2503 a/b + c/d
摘要:1 #include<iostream> 2 3 using namespace std; 4 5 int gcd(int a, int b) 6 { 7 return b?gcd(b, a%b):a; 8 } 9 10 int main()11 {12 int a, b, c, d, m, k;13 int n;14 cin >> n;15 while(n--)16 {17 cin >> a >> b >> c >> d;18 int t=gcd(b,d);19 m=a*d/t+b*c/t;... 阅读全文
posted @ 2012-07-31 14:19 zrq495 阅读(114) 评论(0) 推荐(0)
HDU 1713 相遇周期
摘要:求a/b与c/b的最小公倍数。要求最小公倍数,那么结果肯定是分子尽量小,即 求a , c 的最小公倍数, 分母尽量大, 即求 b , d 的最大公约数。、求最大公约数:int gcd(int a, int b){ return b?gcd(b, a%b):a;}代码: 1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 6 int gcd(int a, int b) 7 { 8 return b?gcd(b, a%b):a; 9 }10 11 int lcm(int a, int b)12 阅读全文
posted @ 2012-07-31 14:13 zrq495 阅读(285) 评论(0) 推荐(0)
HDU 1028 Ignatius and the Princess III
摘要:差不多懂了,解析过程别人写了,代码自己写的。在正整数n的所有不同划分中,将最大加数n1不大于m的划分个数记为q(n,m)。可以建立q(n,m)的如下递归关系:<1> q(n,m) = 1, n >= 1当最大加数n1不大于1时,任何正整数n只有一种划分形式,n = 1 + 1 + 1 +...+ 1<2> q(n,m) = q(n,n), m >= n最大加数n1实际上不能大于n<3> q(n,n) = 1 + q(n,n - 1)正整数n的划分由n1 = n的划分和n1 < n - 1的划分组成<4> q(n,m) = q(n 阅读全文
posted @ 2012-07-31 11:40 zrq495 阅读(224) 评论(0) 推荐(0)
HDU 1715 大菲波数
摘要:大数加法 + 打表。代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 6 using namespace std; 7 8 struct node 9 {10 char s[1000];11 };12 13 int main()14 {15 struct node f[1001];16 int i, j, l, n, m;17 int a[1000], b[1000], r[1000];18 int alen, blen, l 阅读全文
posted @ 2012-07-27 14:33 zrq495 阅读(215) 评论(0) 推荐(0)
hdu 1047 Integer Inquiry
摘要:大数加法。注意:输入100000输出0代码如下: 1 #include<iostream> 2 #include<cstring> 3 using namespace std; 4 int main() 5 { 6 int T, i; 7 char a[1000]; 8 int sum[1000], b[1000]; 9 cin >> T;10 while(T--)11 {12 memset(a, 0, sizeof(a));13 ... 阅读全文
posted @ 2012-07-25 18:41 zrq495 阅读(302) 评论(0) 推荐(0)
堆排序练习 hdu 1425 sort
摘要:不只是堆排序,其他排序也能过,很水的题,拿来练习堆排序的。代码: 1 #include<stdio.h> 2 #include<stdlib.h> 3 4 int a[1000002]; 5 6 void heapadjust(int *a, int k, int n) 7 { 8 int i, j; 9 i=k;10 j=2*i;11 a[0]=a[i];12 while(j<=n)13 {14 if ((j<n) && a[j]>a[j+1])15 j++;16 if (a[0]>a[j])17 {... 阅读全文
posted @ 2012-07-21 19:01 zrq495 阅读(256) 评论(0) 推荐(0)
HDU 1021 Fibonacci Again
摘要:每四个一循环一次。 1 #include<iostream.h> 2 using namespace std; 3 int main() 4 { 5 int n; 6 while(cin>>n) 7 { 8 if (n%4 == 2) 9 cout<<"yes"<<endl;10 else11 cout<<"no"<<endl;12 }13 return 0;14 } 阅读全文
posted @ 2012-02-26 11:13 zrq495 阅读(124) 评论(0) 推荐(0)
HDU 1013 Digital Roots
摘要:Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a single digit then that digit is the digital root. If the resulting value contains two or more digits, those digits are summed and the process is repeated. This is cont 阅读全文
posted @ 2012-02-26 10:26 zrq495 阅读(161) 评论(0) 推荐(0)
HDU 1012 u Calculate e
摘要:水题~Problem DescriptionA simple mathematical formula for e iswhere n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.OutputOutput the approximations of e generated by the above formula for the values of n from 0 to 9. The begi 阅读全文
posted @ 2012-02-25 20:57 zrq495 阅读(209) 评论(0) 推荐(0)
HDU 1005 Number Sequence
摘要:Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to calculate the value of f(n).InputThe input consists of multiple test cases. Each test case contains 3 integers A, B and n on a single line (1 <= 阅读全文
posted @ 2012-02-25 20:39 zrq495 阅读(176) 评论(0) 推荐(0)

上一页 1 2