a*****n 发帖数: 230 | 1 I have been waiting for this for 10 years. But this noon, I saw this line:
The byte code compiler and interpreter now include new instructions that
allow many scalar subsetting and assignment and scalar arithmetic operations
to be handled more efficiently. This can result in significant performance
improvements in scalar numerical code.
I immediately downloaded the latest R build and benchmark against a KD-tree
code I wrote.
R Build from 20 days ago: 8.45 minutes
R build of today: 5.01 minutes
A... 阅读全帖 |
|
l*****0 发帖数: 13 | 2 class Solution {
public:
bool getSum(vector &ratings, int &sum)
{
bool isReverse = false;
int n = ratings.size();
int* candy = new int[n];
memset(candy, 0, n*sizeof(int));
candy[0] = 1;
for (int i=1; i
{
if (ratings[i] > ratings[i-1])
candy[i] = candy[i-1] + 1;
else if (ratings[i] == ratings[i-1])
candy[i] = candy[i-1];
e... 阅读全帖 |
|
l*****0 发帖数: 13 | 3 class Solution {
public:
bool getSum(vector &ratings, int &sum)
{
bool isReverse = false;
int n = ratings.size();
int* candy = new int[n];
memset(candy, 0, n*sizeof(int));
candy[0] = 1;
for (int i=1; i
{
if (ratings[i] > ratings[i-1])
candy[i] = candy[i-1] + 1;
else if (ratings[i] == ratings[i-1])
candy[i] = candy[i-1];
e... 阅读全帖 |
|
h***s 发帖数: 1716 | 4 昨晚回家查了关于entropy的书,我猜的应该可以.
two-lists-of-values-are-same (array1 array2)
loop array1 and array2:
collect sum1, sum2, minimum1, minimum2, N
if NOT (sum1==sum2 & minimum1==minimum2):
return false.
initialize:
sucker1=0, sucker2=0,
normalization=sum1-N*minimum1
loop array1 and array2:
p1 = (element1 - minimum1) / normalization
p2 = (element2 - minimum2) / normalization
sum p1*捞个(p1) into sucker1
sum p2*捞个(p2) into sucker2
if (sucker1==sucker2):
return true;
else
return false.
显然计算时间循 |
|
s*****y 发帖数: 897 | 5 来自主题: JobHunting版 - 一个面试题 create too variable sum1 and sum2, both into to 0.
whenever we get a data from the array, we compare sum1 with sum2. Add the da
ta to the smaller one.
Finally, if sum1 = sum2, we get it.
O(N) |
|
b**********5 发帖数: 7881 | 6 返回每个点左右子树的和与自己值的差?
how should we return this? in a list? or just print it out?
void helper( ) {
if (root == null) return 0;
sum1 = helper(root.left);
sum2 = helper(root.right);
print(sum1+sum2-root.val);
return sum1+sum2+root.val;
} |
|
s*********n 发帖数: 20 | 7 data test;
input ID $ MEDICATION CLASS1 CLASS2 CLASS3;
CARDS;
001 1 1 0 0
001 2 1 0 0
001 3 0 1 0
002 1 1 0 0
002 2 1 0 0
003 1 1 0 0
003 2 0 0 1
;
RUN;
proc means data=test sum;
var class1 class2 class3;
by Id;
output out=test2 sum=sum1 sum2 sum3;
run;
data test3;
set test2(keep=sum1 sum2 sum3);
array hh{*} sum1 sum2 sum3;
do i=1 to dim(hh);
if hh{i}=0 then hh{i}=0;
else hh{i}=1;
end;
drop i;
run; |
|
k*****u 发帖数: 1688 | 8 下面这组data,打算对列求和。 用data step可以如下做,现在打算把
sum1+summer1;
sum2+summer2;
sum3+summer3;
sum4+summer4;
换成用macro来改写,应该怎么写? 折腾了好久都没弄出来,求教。
我试着用array可以做,macro总是说有问题。谁能帮我写一下code? 谢谢
data wide;
input name $ summer1-summer4;
cards;
a 1 2 3 4
b 1 2 3 4
c 1 2 3 4
;
data sum_data;
set wide end=lastobs;
sum1+summer1;
sum2+summer2;
sum3+summer3;
sum4+summer4;
keep sum1-sum4;
if lastobs then output;
run;
proc print data=sum_data;
run; |
|
c**j 发帖数: 103 | 9 求大牛指正,
这个为什么不能求和 sum1
减去 等差数列的和 sum2,因为1 to n-1
sum1-sum2 is the duplicated number? |
|
t******t 发帖数: 21 | 10 how about greedy?
sort the array say {1,2,3, 80, 85, 99, 100, 1000}
pick 1000 first in A1
pick 100 in A2
if (sum1 -sum2)900 > next max 99
pick next min 1 in A1 and next max 99 in A2
else if sum1 > sum2 pick next max in A2, then repeat recursively |
|
d****n 发帖数: 233 | 11 抛个砖:
typedef struct {
int L;
int W;
} Dimension;
bool compareLW(const Dimension &l, const Dimension &r)
{
if (l.L == r.L) return l.W > r.W;
return l.L > r.L;
}
void normalize(Dimension &dimen)
{
if (dimen.L > dimen.W) {
int t = dimen.L;
dimen.L = dimen.W;
dimen.W = t;
}
}
int MinArea(vector dimens)
{
if (dimens.size() < 1) return 0;
for(int i = 0; i < dimen... 阅读全帖 |
|
d****n 发帖数: 233 | 12 抛个砖:
typedef struct {
int L;
int W;
} Dimension;
bool compareLW(const Dimension &l, const Dimension &r)
{
if (l.L == r.L) return l.W > r.W;
return l.L > r.L;
}
void normalize(Dimension &dimen)
{
if (dimen.L > dimen.W) {
int t = dimen.L;
dimen.L = dimen.W;
dimen.W = t;
}
}
int MinArea(vector dimens)
{
if (dimens.size() < 1) return 0;
f... 阅读全帖 |
|
Y**G 发帖数: 1089 | 13 下面的代码我测试通过了。
public class Rect {
int x;
int y;
int width;
int height;
public Rect(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
public int getArea() {
return width * height;
}
Rect intersect(Rect other) {
int newX0 = Math.max(x, other.x);
int newY0 = Math.max(y, other.y);
int newX1 = Math.min(x + width, other.x + other.width);
in... 阅读全帖 |
|
c***n 发帖数: 921 | 14 Table A: 3 attributes (id, qty, date) e.g. row (a001, 50, 200705)
Now want to produce a table B which contains 3 attributes (id, sum1, sum2)
sum1= sum(qty) between 200705 and 200804
sum2 = sum(qty) between 200605 and 200704
Is there any smart method to get table B? |
|
r****y 发帖数: 1437 | 15 Friend asked me this question and I have no clue how to do it
A set of numbers, sqrt(1), sqrt(2), ..., sqrt(50)
You divide these 50 numbers into two group, the sum of the
first group is sum1, the sum of the second group is sum2, let
dsum = abs(sum1 - sum2)
question, how you divide these 50 numbers to make dsum as small as
possible?
The gut is dsum could be very small, -> 0. But no idea how to prove
and how to find those two sets. Hehe.
|
|
m****u 发帖数: 229 | 16 Didn't sum1 by 100 at&t Samsaung A107 @ $4.99 USD each from Worst Buy 3-6
months ago?
I want to sell mine @ $13.99+ your label.
Pls buy so I can BSO a 200%+ return. |
|
m****k 发帖数: 1067 | 17 假设有n个milestones,
1, 对给的array排序
2, 最大-第二大= 头or 尾
3, 建n-2个hashtable, 每个table是从 2个milstones的和到n-1个milestones的和
4, 在n-1个milestone的和的hashtable里找 sum= 最大-头or尾的milestones的组合
5, 在n-2个milestones的和的table里找 sum1=sum- 任意4里找出来的组合的一个
mileston
e,
继续这么找下去直到结束。。
不过忒麻烦了。。 |
|
m****k 发帖数: 1067 | 18 假设有n个milestones,
1, 对给的array排序
2, 最大-第二大= 头or 尾
3, 建n-2个hashtable, 每个table是从 2个milstones的和到n-1个milestones的和
4, 在n-1个milestone的和的hashtable里找 sum= 最大-头or尾的milestones的组合
5, 在n-2个milestones的和的table里找 sum1=sum- 任意4里找出来的组合的一个
mileston
e,
继续这么找下去直到结束。。
不过忒麻烦了。。 |
|
w***t 发帖数: 1474 | 19 万一2sum和target-2sum这两个sum包含同一个元素咋办。
sum1 = a + b;
sum2 = a + c;
target = a + a + b + c; 这样是错的把
值, |
|
w***t 发帖数: 1474 | 20 万一2sum和target-2sum这两个sum包含同一个元素咋办。
sum1 = a + b;
sum2 = a + c;
target = a + a + b + c; 这样是错的把
值, |
|
c********t 发帖数: 5706 | 21 哦,明白了,我测得有问题。
你的这个解太牛了,我花了很久,读了以前的帖子,才明白。理解以后,觉得好简练,
而且其实也很容易理解。
佩服!
有一道变体题,最大路径定义为“两点间最大路径sum1,加上common ancestor到root的
路径。”请问可有好的解? |
|
c***n 发帖数: 921 | 22 200705 是 date, 不是id.
id qty date
a01 50 200601
a01 55 200604
a01 60 200605
a01 50 200701
a01 55 200702
a01 60 200704
a01 45 200805
a01 55 200806
a02 50 200603
a02 55 200604
a02 60 200608
a02 50 200703
a02 55 200704
a02 60 200705
a02 45 200801
a02 60 200804
a02 55 200806
a03 10 200807
期望得到
id sum1(200605-200704 sum) sum2(200705-200804 sum)
a01 225 null (or 0)
a |
|
h******e 发帖数: 1791 | 23 我的问题是这样的:
用proc means计算dataset里所有numeric variable的sum,sas code为:
output out = out sum(v_1 -- v_last) = sum1 - sum&outvar;
&outvar代表着variable的总数。 |
|
s******r 发帖数: 1524 | 24 %macro Test(Countt);
data sum_data;
set wide end=lastobs;
%do i =1 %to &Countt;
sum&i+summer&i;
%end;
keep sum1-sum&Countt;
if lastobs then output;
run;
%mend;
%Test(4);
错了不管。 |
|
k*****u 发帖数: 1688 | 25 确实是对的
能不能再帮我看看,我这么写为什么不对
%macro sumv(maxobs=);
%do i=1 %to &maxbos;
asum&i+summer&i
%if &i ne &maxobs %then ;
;
%end;
%mend;
data sum_data;
set wide end=lastobs;
%sumv(maxobs=4);
keep sum1-sum4;
if lastobs then output;
run; |
|
a*****3 发帖数: 601 | 26 话说没人喜欢看别人code where there are even typos not cleared (maxbos?). The
%if %then is also used in a weird fashion. Your code worked okay after i
deleting everything i did not understan:
%macro sumv(maxobs=);
%do i=1 %to &maxobs;
sum&i+summer&i ;
%end;
%mend sumv;
option mlogic mprint symbolGEN;
data sum_data;
set wide end=lastobs;
%sumv(maxobs=4) ;
keep sum1-sum4;
if lastobs then output;
run;
杀牛给点伪币吧 马上到年关了 |
|