avatar
l*r
1
1. Int to string (pay attention to the smallest negative number)
2. Given two sorted list, find the k smallest number (binary search)
3. You can win three kinds of basketball points, 1 point, 2 points, and 3
points. Given a total score X, print out all the combination to compose X. (
recursion/ Dp)
4. Given a stream of integers, at a given time, there is a number appeared
more than half time, how to find this number. (classic streaming algorithm
)
avatar
r*d
2
Here is an example to show how stupid the tax form is:
page A-11
step 10. Divide line 9 by 1.5 (ok it is X 2/3)
step 11. Subtract line 10 from line 9 (isn't it 1 - 2/3 = 1/3 of line 9? )
Why shall we do it in 2 steps while we can do this easily by one step?
The problem is that I lose $$$ from the stupidity:
1. You can count state income tax in itemized deduction. Under certain cases
, you cannot get the full amount of the itemized deduction. So let's say you
get (state tax + other items) X 90% a
avatar
s*t
3
ding
总看到itoa的题目,弱弱地问一下,是不是sprintf,ssteram之类的都不许用?
第四个题没想法

(
algorithm

【在 l*********r 的大作中提到】
: 1. Int to string (pay attention to the smallest negative number)
: 2. Given two sorted list, find the k smallest number (binary search)
: 3. You can win three kinds of basketball points, 1 point, 2 points, and 3
: points. Given a total score X, print out all the combination to compose X. (
: recursion/ Dp)
: 4. Given a stream of integers, at a given time, there is a number appeared
: more than half time, how to find this number. (classic streaming algorithm
: )

avatar
H*7
4
所以要用软件啊。不然会恶心死
avatar
m*g
5
3是coin change的一种。就是每个都试,不算dp
4前面讨论过好象,就是用一个counter计数
cnt = 0;
curNum = 0;
while(input>>temp)
{
if(!cnt) curNum = temp;
if(temp == curNum)
cnt++;
else
cnt--;
}
大概就是这样
avatar
b*p
6
这么笨的tax form你都能loss $$, 岂不是说明你更笨?
avatar
f*4
7
lz 面的啥职位?这4道都要求写代码么?
Given two sorted list, find the k smallest number
这个能用binary search么?谁给解释一下咋用binary search
保证list都是从小到大排序,2个list分别scan,输出小的那个值,然后那个指针后移
;得到k个停止
avatar
r*d
8
The tax form clearly says that you have to use the numbers in your fed form
even if your deduct is limited. So it is intentionally made like that even
though it does not make sense to me. All software will do the same thing. It
is just like you can say a law is stupid, but it does not mean you can
break the stupid law.
Do not play any tricks in tax return!

【在 b********p 的大作中提到】
: 这么笨的tax form你都能loss $$, 岂不是说明你更笨?
avatar
s*t
9
这个很直观
binary就是只保留两数组的头K个
然后比a[k/2],b[k/2],每次缩小一般搜索范围
如果list指的是链表那还是算了。。

【在 f****4 的大作中提到】
: lz 面的啥职位?这4道都要求写代码么?
: Given two sorted list, find the k smallest number
: 这个能用binary search么?谁给解释一下咋用binary search
: 保证list都是从小到大排序,2个list分别scan,输出小的那个值,然后那个指针后移
: ;得到k个停止

avatar
f*4
10
恩,我的意思就是list的binary search。。。
顺带的,大家都是在哪里看这些题目啊?精华区?

【在 s*********t 的大作中提到】
: 这个很直观
: binary就是只保留两数组的头K个
: 然后比a[k/2],b[k/2],每次缩小一般搜索范围
: 如果list指的是链表那还是算了。。

avatar
c*f
11
谢谢!也问lz面的什么职位?
avatar
k*n
12
re
avatar
t*n
13
第四题对消法,如果两个整数不一样就消除
一样就计数

(
algorithm

【在 l*********r 的大作中提到】
: 1. Int to string (pay attention to the smallest negative number)
: 2. Given two sorted list, find the k smallest number (binary search)
: 3. You can win three kinds of basketball points, 1 point, 2 points, and 3
: points. Given a total score X, print out all the combination to compose X. (
: recursion/ Dp)
: 4. Given a stream of integers, at a given time, there is a number appeared
: more than half time, how to find this number. (classic streaming algorithm
: )

avatar
b*9
14
第四题题目没有看懂啊。有谁能解释一下?多谢!
对消。。。计数。。。以前版上有讨论么?
哪位来帮忙解释一下!多谢!
avatar
l*a
15
count=0;
for(int i=0;i{
if(count==0){temp=a[i];count++;}
else{ if(temp!=a[i]){count--;}
else count++;
}
}
return temp;

【在 b********9 的大作中提到】
: 第四题题目没有看懂啊。有谁能解释一下?多谢!
: 对消。。。计数。。。以前版上有讨论么?
: 哪位来帮忙解释一下!多谢!

avatar
a*1
16
每次删除2个不同的数,那剩下的数中,那个target出现的次数仍然超过总数的一半。
int nTimes = 0;
int target = 0;
for(int i=0; iif(nTimes==0){
target = a[i];
nTimes = 1;
} else {
if(target==a[i])
nTimes++;
else
nTimes--;
}
}
return target;
avatar
b*9
17
对吗?
int a[7] = {1,2,2,2,3,3,3};
算完后, nTimes = 1; Target = 3;
3没有超过一半的出现次数

【在 a*******1 的大作中提到】
: 每次删除2个不同的数,那剩下的数中,那个target出现的次数仍然超过总数的一半。
: int nTimes = 0;
: int target = 0;
: for(int i=0; i: if(nTimes==0){
: target = a[i];
: nTimes = 1;
: } else {
: if(target==a[i])
: nTimes++;

avatar
a*1
18
题目的要求是at a given time, there is a number appeared more than half time,
how to find this number. Assumption就是要有一个数出现次数超过半数吧.
avatar
b*9
19
你是对的。我忽略了这个assmuption。
有这个assumption,其实题目就转化为求出现次数最多的数。出现最多的数也就是出现
超过一半的那个数。所以大家一起对消,最后剩下的总是出现次数最多的那个数。
另外,之前完全误解了题目意思。题目应该编辑为more than half times不是more
than half time。。是次数。。不是时间。。。:)

time,

【在 a*******1 的大作中提到】
: 题目的要求是at a given time, there is a number appeared more than half time,
: how to find this number. Assumption就是要有一个数出现次数超过半数吧.

avatar
j*u
20
3要注意按一定顺序(比如开始用2了就不能再用3了),因为1 3 1和3 1 3算一种

【在 m*****g 的大作中提到】
: 3是coin change的一种。就是每个都试,不算dp
: 4前面讨论过好象,就是用一个counter计数
: cnt = 0;
: curNum = 0;
: while(input>>temp)
: {
: if(!cnt) curNum = temp;
: if(temp == curNum)
: cnt++;
: else

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。