码迷,mamicode.com
首页 >  
搜索关键字:k sum    ( 21381个结果
Triangle
Triangle  Total Accepted: 16109 Total Submissions: 60327My Submissions Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row...
分类:其他好文   时间:2014-08-23 16:54:11    阅读次数:253
LeetCode——3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact...
分类:其他好文   时间:2014-08-23 16:51:01    阅读次数:184
LeetCode——4Sum
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target. Note: Element...
分类:其他好文   时间:2014-08-23 16:49:21    阅读次数:166
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 in a triplet (a,b,c...
分类:其他好文   时间:2014-08-23 15:24:41    阅读次数:153
04-3. 统计素数并求和(20)
时间限制400 ms内存限制32000 kB代码长度限制8000 B判题程序Standard作者张彤彧(浙江大学)本题要求统计给定整数M和N区间内素数的个数并对它们求和。输入格式:输入在一行中给出2个正整数M和N(1int main(){ int M,N,count=0,sum=0,i,j; s.....
分类:其他好文   时间:2014-08-23 12:32:20    阅读次数:711
POJ 2029
二维树状数组可解此题#include #include #include #include #define lowbit(x) (x)&(-x)using namespace std;int sum[105][105],k,n,m;int W,H;void gp(int x,int y){ int ...
分类:其他好文   时间:2014-08-23 11:10:50    阅读次数:154
hdu1730 Northcott Game,Nim-sum
题解: 转化成求Nim-sum 每行黑白棋的初始间距作为每堆石子个数 如果当前为P态,则不管当前选手怎样操作,下一个选手都能使其操作后的局面又变为P态。 Nim-sum = 0,即P态。 #include #include #include #include using namespace std; int main() { int n, m; while(...
分类:其他好文   时间:2014-08-23 10:02:50    阅读次数:274
Leetcode - Binary Tree Maximum Path Sum
解题的关键在于这条路径只能是先往上走,到达某个最高点,再往下走,换句话说,只能有一次转折的机会。所以递归这棵树,记录以某个子节点为转折点时的最大值。值得注意的是树节点的值有负值,所以如果某个子路径的和小于0,放弃它(设置和为0)。 class Solution { public: int maxPathSum(TreeNode *root) { int maxSum = -1 <...
分类:其他好文   时间:2014-08-23 10:01:00    阅读次数:167
打印二叉树节点数值总和等于某个给定节点的所有路径
打印二叉树节点数值总和等于某个给定节点的所有路径,路径可以从任意节点开始,任意节点结束。比如,假设和是8,树如下 的路径有 [[5,3],[8],[5,1,2]]。 5 / \ 3 1 /\ /\4 8 2 6思路:遍历所有路径,对于每一个节点,在其路径中向后寻找sum和为targ...
分类:其他好文   时间:2014-08-22 23:50:59    阅读次数:340
poj 1844 Sum 【数学】
题意:给出一个数,让你求从1按照顺序来加减并且你可以改变任意两个数之间的符号. 分析: 对于1~n这n个数(和为sum),可以组成任意的1~sum之间的数,并且改变一个数n(例如 1+2+3+4+5, 将2前面的符号改为-) 那么这n个数的和就减小了2*n(例子中就减少了4),既然这样我们只需要找出大于等于要求的数的数n(就是大于给定数的1~n的和),在判断(总和-n)是不是偶数就可以了。不明白的话,直接看代码; 代码:...
分类:其他好文   时间:2014-08-22 22:34:16    阅读次数:198
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!