摘要: uva 11424 GCD - Extreme (I)题意:思路:(见http://www.cnblogs.com/Duahanlang/p/3184994.html)差别在于数据规模和时间,其他一下,同样的思路,同样的做法代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 typedef long long LL;10 const int N = 200005;11 int e[N];12 LL tag[N];13 14 void eul... 阅读全文
posted @ 2013-08-02 11:32 妮king狼 阅读(334) 评论(0) 推荐(0)
摘要: lightoj 1214 Large Division (大数除法)链接:http://www.lightoj.com/volume_showproblem.php?problem=1214题意:给定 a, b 两个数,判断 a 是否整除 b 。(a 为 大数)思路: 用字符串存 a ,转化为 整型数组,用除法原理进行处理,没什么难度。其中关键是负号的处理。代码: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 9 typedef long lon... 阅读全文
posted @ 2013-08-01 10:03 妮king狼 阅读(337) 评论(0) 推荐(0)
摘要: Leading and Trailinglightoj 链接:http://lightoj.com/volume_showproblem.php?problem=1282uva 链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1970题意:给定 n, k ,求 nk 的前3位和后三位的值。思路:1、前 3 位:把 nk 转化为 a.bc * 10m,两边取 10 的对数得到 k * lg(n) = m + lg(a.bc) 阅读全文
posted @ 2013-07-29 17:50 妮king狼 阅读(448) 评论(0) 推荐(0)
摘要: lightoj 1341 Aladdin and the Flying Carpet链接:http://lightoj.com/volume_showproblem.php?problem=1341题意:给定整数 a, b ,求 区间[b, a] 内的 a 的约数对的个数,a 的约数对(比如[2, 3] 与 [3, 2] 是同一对),也就是说前因子要小于后因子。思路:我的思路比较直接,就是求a 的约数的个数(用欧拉函数),除以 2 就得到约数对数, 然后暴力求解区间 [1, b]内的 a 的约数。最后两数相减得到结果。代码: 1 #include 2 #include 3 #include.. 阅读全文
posted @ 2013-07-29 11:07 妮king狼 阅读(609) 评论(0) 推荐(0)
摘要: zoj 2369 Two Cylinders链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2369题意:已知两个无限长的圆柱的半径,它们轴线相交且垂直,求相交部分的体积。思路:以相交点为坐标原点,建立三维坐标系,列出 两个圆柱的公式,把三维转化为一维积分公式 V1 : x2 + y2 = r12 ==> y = sqrt ( r12 - x2 ); V2 : x2 + z2 = r22 ==> z = sqrt ( r22 - x2 ); V =∫∫∫ dv =∫∫∫ dxdydz ... 阅读全文
posted @ 2013-07-27 11:09 妮king狼 阅读(332) 评论(0) 推荐(0)
摘要: 素数的求解是数论题目中频繁遇到的问题,下面介绍几种求 n 以内的素数的算法全局定义:1 const int n = ?; //n范围2 const int ma = ?; //素数个数3 bool nu[n]; //标记数组4 int phi[ma]; //存素数5 1、较为高效的筛法 思想:从 2 开始,即标记数组为0(或为1),当标记数组为 0(或1) 时,该数为素数,把素数的倍数筛掉。此算法缺陷在于会重复筛选有不同素数因子的合数(比如说6,被2筛一次,又被3筛一次)代码: 1 void prim... 阅读全文
posted @ 2013-07-24 20:23 妮king狼 阅读(1726) 评论(0) 推荐(0)
摘要: lightoj 1245Harmonic Number (II)题意:给定一个 n ,求 n/1 + n/2 + …… + n/n 的值(这里的 "/" 是计算机的整数除法,向下取整)。思路:唉,想了很久,最终还是没什么好方法。我的思路是这样的: 记录结果为 n/1,n/2,……,n/n的有多少个,然后乘以各自的值就得到结果了。唉暴搞的人桑不起,2.2s过了,膜拜 oj 里边 100+ms过的大神。代码: 1 #include 2 #include 3 using namespace std; 4 5 typedef long long LL; 6 7 int main() 阅读全文
posted @ 2013-07-22 20:39 妮king狼 阅读(389) 评论(0) 推荐(0)
摘要: hdoj 1299 Diophantus of Alexandria链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299题意:求 1/x + 1/y = 1/n (x 2 #include 3 #include 4 #include 5 using namespace std; 6 7 typedef long int LL; 8 const int maxv = 35000; 9 int prime[4000], num[maxv];10 11 void prim() //筛法求素数12 {13 int i, j, k = 1;... 阅读全文
posted @ 2013-07-21 20:19 妮king狼 阅读(245) 评论(0) 推荐(0)
摘要: 求前n项正整数的倒数和 前n项正整数的和是一个发散的序列,学过高等数学的这个都知道。所以它没有一个精确的公式,但是近似的公式是有的: 1 + 1/2 + 1/3 + …… + 1/n ≈ ln n + γ, 其中 γ 是欧拉常数, 值为 γ=0.577215,66490,15328,60606,51209,00824,02431,04215,93359,39923,59880,57672,34…证明:根据Newton的幂级数有: ln(1+1/x) = 1/x - 1/2x^2 + 1/3x^3 - ... 于是: 1/x = ln((x+1)/x) + 1/2x^2 - ... 阅读全文
posted @ 2013-07-19 13:19 妮king狼 阅读(2611) 评论(0) 推荐(0)
摘要: lightoj 1007 - Mathematically Hard链接:http://www.lightoj.com/volume_showproblem.php?problem=1007题意:给定一个区间[m, n],假设 小于m的与m互质的数的个数为 s(m),小于m+1的与m+1互质的数的个数为 s(m+1),……,小于n的与n互质的数的个数为 s(n)。如果 m == n,输出 a = s(m)*s(m),否则,输出 a = s(m)*s(m) + s(m+1)*s(m+1) + …… + s(n)*s(n)。数据规模为maxv = 5 * 10^6思路:求出maxv内的所有数的 a 阅读全文
posted @ 2013-07-15 21:20 妮king狼 阅读(382) 评论(0) 推荐(0)