码迷,mamicode.com
首页 >  
搜索关键字:max sum plus plus    ( 46271个结果
LeetCode: Pow(x, n) [049]
【题目】 Implement pow(x, n). 【题意】 实现pow(x, n) 【思路】 最直接的思路是用一个循环,乘n次的x。 当n的值较小的时候还好,当n非常大时,时间成本就非常高。加入n=INT_MAX, 也就是21亿多次循环,你可以试想一下。 在这种情况下,我们需要快速的乘完n个x,采用尝试贪心的方法,即滚雪球方式的翻倍相乘 注意:几种特殊情况 1. n=0; 2. n<0;...
分类:其他好文   时间:2014-05-26 04:37:31    阅读次数:212
欧拉项目010:2000000以内的素数和
Summation of primes Problem 10 The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. 还是使用Sieve of Eratosthenes 算法 我的python代码如下: ...
分类:其他好文   时间:2014-05-26 03:40:15    阅读次数:243
51系列小型操作系统精髓 简单实现10 C语言版优化后发布(有图)
4个任务   /* 使用keil4 可运行8个任务 任务从rtos_wait()处切换,在定时时间到后从定时中断中切换回来。 */ #include "STC12C5A.H" #define TIMER_RELOAD() {TL0=0x00;TH0=0xC4;}//使能T/C 初始10ms #define MAX_TASKS 8 //任务槽最大个数. unsig...
分类:编程语言   时间:2014-05-25 02:03:17    阅读次数:293
Scala 函数
scala> def max(x: Int,y: Int): Int...
分类:其他好文   时间:2014-05-25 01:05:16    阅读次数:405
LeetCode:3Sum
题目:         Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique  triplets in the array which gives the sum of zero. Note: Elements...
分类:其他好文   时间:2014-05-25 00:39:37    阅读次数:343
poj 3463 Sightseeing(最短路+次短路)
http://poj.org/problem?id=3463 大致题意:给出一个有向图,从起点到终点求出最短路和次短路的条数之和。 解法: 用到的数组:dis[i][0]:i到起点的最短路,dis[i][1]:i到起点的严格次短路 vis[i][0],vis[i][1]:同一维的vis数组,标记距离是否已确定 sum[i][0]:i到起点的最短路条数,sum[i][1]:...
分类:其他好文   时间:2014-05-24 21:50:31    阅读次数:287
2014百度之星资格赛——XOR SUM
2014百度之星资格赛——XOR SUM Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。P...
分类:其他好文   时间:2014-05-24 20:53:55    阅读次数:266
Leetcode的bug测试用例 ?? jump game
之所以说leetcode的测试用例有问题,是因为我刚开始理解错了题意,写下了如下的错误的代码。但是却AC了。 错误代码为: bool canJump(int A[], int n) { if(n == 0) return true; int sum = 0; //记录当前的最远距离 int i = 0; ...
分类:其他好文   时间:2014-05-24 19:45:57    阅读次数:1081
2014 百度之星 1003 题解 Xor Sum
Xor Sum Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了N个正整数,随后 Prometheus 将向 Zeus 发起M次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。Prometheus 为了让 Zeu...
分类:其他好文   时间:2014-05-24 17:53:54    阅读次数:177
Light0J-1068 - Investigation
An integer is divisible by 3 if the sum of its digits is also divisible by 3. For example, 3702 is divisible by 3 and 12 (3+7+0+2) is also divisible by 3. This property also holds for the integer 9. ...
分类:其他好文   时间:2014-05-24 14:30:47    阅读次数:208
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!