由买买提看人间百态

topics

全部话题 - 话题: pos1
1 (共1页)
s******n
发帖数: 3946
1
来自主题: JobHunting版 - 说好得FG面经,回馈板上GGJJ
递归非DP做法
bool isScramble(char* str1, char* str2, int length) {
if (length==1) return *str1 == *str2;
for (int i=1; i if (isScramble(str1, str2+(length-i), i)
&& isScramble(str1+i, str2, length-i))
return true;
if (isScramble(str1, str2, i)
&& isScramble(str1+i, str2+i, length-i))
return true;
}
return false;
}
递归DP做法
class Solution {
char* str1;
char* str2;
int m;
int m2;
int m3;
int* DP;
#define dp(i,j,k) DP[m2 * (i) + m * (j) + (k) ]
public:
Solution(cha... 阅读全帖
y****n
发帖数: 15
2
在32核的服务器上,运行一小段图像卷积的操作。输入是图像矩阵(按列),和一个y
方向上的卷积kernel。举例来说,如果kernel是[-0.5 0 0 0 1 0 0 0 0.5],那么下面
程序中的变量分别为
kernel: [-0.5 1 0.5]
szKernel: 3
step: 4
这段程序中使用了OpenMP对for循环执行并行操作。当使用>4个核时,程序运行速度反
而下降。这段程序要运行很多次,是整个程序的性能瓶颈,请大牛们指点一下该如何改
进。
double s = kernel[(szKernel-1)/2];
//#pragma omp parallel for
for (int k = 0; k < m*n; k++)
v_out[k] = v_in[k] * s;
for (int k = 0; k < (szKernel-1)/2; k++)
{
double s = kernel[k];
int offset = ((szKernel-1)/2 - k)*step;
... 阅读全帖
y****n
发帖数: 15
3
在32核的服务器上,运行一小段图像卷积的操作。输入是图像矩阵(按列),和一个y
方向上的卷积kernel。举例来说,如果kernel是[-0.5 0 0 0 1 0 0 0 0.5],那么下面
程序中的变量分别为
kernel: [-0.5 1 0.5]
szKernel: 3
step: 4
这段程序中使用了OpenMP对for循环执行并行操作。当使用>4个核时,程序运行速度反
而下降。这段程序要运行很多次,是整个程序的性能瓶颈,请大牛们指点一下该如何改
进。
double s = kernel[(szKernel-1)/2];
//#pragma omp parallel for
for (int k = 0; k < m*n; k++)
v_out[k] = v_in[k] * s;
for (int k = 0; k < (szKernel-1)/2; k++)
{
double s = kernel[k];
int offset = ((szKernel-1)/2 - k)*step;
... 阅读全帖
k*****y
发帖数: 744
4
来自主题: JobHunting版 - 一道google 经典题
考虑六种从小到大排列的可能情况,每种找出最小的distance,再一起比较。
import random
# generate random data
data = [[],[],[]]
for i in range(0,3):
N = random.randint(5, 10)
for j in range(0, N):
data[i].append(random.randrange(0, 1000))
data[i].sort()
test_cases = [(0,1,2), (0,2,1),
(1,0,2), (1,2,0),
(2,0,1), (2,1,0)]
pos = [[]]*len(test_cases)
dist = [1000000]*len(test_cases)
def LowerBound(x, queueID, start):
for i in range( start, len(data[queueID]) ):
if data[queu... 阅读全帖
k*****y
发帖数: 744
5
来自主题: JobHunting版 - 一道google 经典题
考虑六种从小到大排列的可能情况,每种找出最小的distance,再一起比较。
import random
# generate random data
data = [[],[],[]]
for i in range(0,3):
N = random.randint(5, 10)
for j in range(0, N):
data[i].append(random.randrange(0, 1000))
data[i].sort()
#=============================
test_cases = [(0,1,2), (0,2,1),
(1,0,2), (1,2,0),
(2,0,1), (2,1,0)]
pos = [[] for i in range(len(test_cases))]
dist = [1000000]*len(test_cases)
def LowerBound(x, queueID, start):
for i in range( st... 阅读全帖
g*******y
发帖数: 1930
6
来自主题: JobHunting版 - 微软一个面试题
int k = 1; while(k for(int i=2; i<=k;i=i<<1){ //k是刚刚大于等于N的某个2的整次方数
for(int j=0;j int pos1 = j, pos2 = j+i/2;
if(pos2>=N) continue;
//找当前这段,左半边第一个正数
while(arr[pos1]<0 && pos1 //找当前这段,右半边第一个正数
while(pos2 if(pos1 == j+i/2 || pos2==j+i/2) continue;
//开始对换左边的所有正数和右边的所有负数
int p1 = pos1, p2 = pos2-1;
while(p1 p1 = pos1; p2 =
U***A
发帖数: 849
7
暴力法行吗?
bool matchPatternHelper(string s, int pos1, string q, int pos2, map string> &mp){
if(pos1 == s.length() && pos2 == q.length()){
return true;
}
else if((pos1 < s.length() && pos2 == q.length()) || (pos1 == s.
length() && pos2 < q.length())){
return false;
}

for(int i=pos1+1; i string s1 = s.substr(pos1, i-pos1+1);
if(mp.find(q[pos2]) == mp.end()){
mp.ins... 阅读全帖
U***A
发帖数: 849
8
暴力法行吗?
bool matchPatternHelper(string s, int pos1, string q, int pos2, map string> &mp){
if(pos1 == s.length() && pos2 == q.length()){
return true;
}
else if((pos1 < s.length() && pos2 == q.length()) || (pos1 == s.
length() && pos2 < q.length())){
return false;
}

for(int i=pos1+1; i string s1 = s.substr(pos1, i-pos1+1);
if(mp.find(q[pos2]) == mp.end()){
mp.ins... 阅读全帖
c*********e
发帖数: 16335
9
void myOperation(...,int OPER) {

v_out[pos1] = ( OPER == -1 ? (v_in[pos1] - v_in[pos2] ): (v_in[pos1] + v_
in[pos2] ) );

如下面的一段代码,倒数第2行 OPER 可以是 + 或 -
如果不希望把把 + 和 - 分别写成不同的函数,有什么办法么?
这段代码对性能的要求比较高,所以不想用lambda表达式。
void add(...) {...}
void subtract(...) {...}
...
for (int x = 0; x < n - offset; x++)
{
long pos1 = x * m;
long pos2 = (x + offset) * m;
for (int y = 0; y < m; y++, pos1++, pos2++)
v_out[pos1] = v_in[pos1] OPER v_in[pos2];
}
...
l*********s
发帖数: 5409
10
来自主题: Statistics版 - Weird SAS macro bugs, 包子重谢!
I am having some very weird bug while trying to write a macro that can
expend the short hand notion like var1--var11 used in SAS.
The "shorthand" macro works fine on its own, but fails to work when called
by the "formula" macro. The error message seems to say that "the set
statement in the data step is not valid or not in proper order", what's
going on?
Many thanks!
////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////... 阅读全帖
k**********g
发帖数: 989
11
template
struct add_op {
T operator () (const T& src0, const T& src1) const
{ return src0 + src1; }
};
template
struct sub_op {
T operator () (const T& src0, const T& src1) const
{ return src0 - src1; }
};
template
class vec_apply {
void operator () (T* v_out, T* vec_in, long len, ...)
{
oper op; // creates a oper object (functor) on stack - does not take
space, because it will be optimized away when compiler find... 阅读全帖
k*k
发帖数: 49
12
来自主题: JobHunting版 - 微软一个面试题
@geniusxsy:
这个算法是 nlogn 吗?
1) while(k log N
2) for(int i=2; i<=k;i=i<<1) ==> log K
3) for(int j=0;j N/i == N/log K
4) the content of the inner most loop seems to me has N complexity worst
case.
so seems to me 2)*3)*4) already N^2
很可能是我哪里没搞明白。。。
先谢谢了。
int k = 1;
while(k for(int i=2; i<=k;i=i<<1){ //k是刚刚大于等于N的某个2的整次方数
for(int j=0;j int pos1 = j, pos2 = j+i/2;
if(pos2>=N) continue;
//找当前这段,左半边第一个正数
while(arr[pos1]<0 && pos1 //找当前这段,右半边第
y****n
发帖数: 15
13
如下面的一段代码,倒数第2行 OPER 可以是 + 或 -
如果不希望把把 + 和 - 分别写成不同的函数,有什么办法么?
这段代码对性能的要求比较高,所以不想用lambda表达式。
void add(...) {...}
void subtract(...) {...}
...
for (int x = 0; x < n - offset; x++)
{
long pos1 = x * m;
long pos2 = (x + offset) * m;
for (int y = 0; y < m; y++, pos1++, pos2++)
v_out[pos1] = v_in[pos1] OPER v_in[pos2];
}
...
c*******9
发帖数: 9032
14
来自主题: Programming版 - 围棋规则haskell表示
http://homepages.cwi.nl/~tromp/go/Go.hs
{-# LANGUAGE ScopedTypeVariables #-}
module Go where
import Data.Ix
import Data.List
import Data.Array
import Control.Monad
import Control.Monad.State
data Player = Black | White deriving (Eq, Enum, Show)
data Color = Empty | Stone Player deriving (Eq, Show)
newtype Position p = Position (Array p Color) deriving (Eq)
color :: (Point p) => Position p -> p -> Color
color (Position pos) p = pos!p
class (Show p, Ix p) => Point p where
pointBounds :: (p,p)
... 阅读全帖
r****c
发帖数: 1494
15
你贴图敢贴个高清的么????
_http://bbs.zhibo8.com/thread-685892-1-1.html
这里有稍高清晰度的。你看阴影!阴影比脚还粗!
这个图表现物体从position1到pos2的过渡(pos2是虚化的)
你看pepe的腿只有在position2 才能碰到假设在pos1的a2的小腿,而同时
a2的小腿已经在pos1和pos2之间(pos2有半透明的小腿)
你敢看看高清的视频么???
是有过渡的一桢里两者在二维的视频图像让两者重叠的,有些少空间想象
能力的人也会告诉你两者没有碰在一起。
http://www.tudou.com/player/outside/player_outside.swf?iid=80962997&snap_pic=http%3A%2F%2Fi4.tdimg.com%2F080%2F962%2F997%2Fw.jpg&default_skin=http%3A%2F%2Fjs.tudouui.com%2Fbin%2Fplayer2%2Foutside%2FSkin_outside_70.swf&autostart=false&auto... 阅读全帖
y****n
发帖数: 15
16
多谢你的指点。
我按下面方式定义macro,用visual studio 2008编译。
但在实际执行add()时,执行的却是减法操作。
如果在add()和subtract()的最后加上"#undef OPER",则会出现编译错误,提示在foo
中找不到OPER的定义。
void add(...)
{
#define OPER +
foo(...)
}
void subtract(...)
{
#define OPER -
foo(...)
}
void foo(...)
{
...
v_out[pos1] = v_in[pos1] OPER v_in[pos2];
...
}

expression
t****t
发帖数: 6806
17
no, that's not how macro works. to use macro, you need to write:
define FOO \
{ \
/*...*/ \
v_out[pos1] = v_in[pos1] OPER v_in[pos2]; \
}
#define OPER +
void add(...)
FOO
#undef OPER
#define OPER -
void subtract(...)
FOO
#undef OPER
it's not a very pleasant solution, of course. i won't recommend that.

foo
N8
发帖数: 110
18
template

no, that's not how macro works. to use macro, you need to write:
define FOO \
{ \
/*...*/ \
v_out[pos1] = v_in[pos1] OPER v_in[pos2]; \
}
#define OPER +
void add(...)
FOO
#undef OPER
#define OPER -
void subtract(...)
FOO
#undef OPER
it's not a very pleasant solution, of course. i won't recommend that.
foo
b*****s
发帖数: 187
19
这场比赛? 官方数据讲话
Pos4: 65 vs 61
Pos3: 75 vs 64
Pos2: 76 vs 85
Pos1: 83 vs 84
http://www.vancouver2010.com/olympic-curling/schedule-and-results/womens-
round-robin-session-11_cuw400943hL.html
k*k
发帖数: 49
20
来自主题: JobHunting版 - 微软一个面试题
miss this line...
int pos1 = j, pos2 = j+i/2;
thanks
k*k
发帖数: 49
21
来自主题: JobHunting版 - 微软一个面试题
is your array rotation technique generally applicable?
given an array such as
[+ + + + - - -]
i will do following:
1) compute the len of neg. segement
2) reverse the whole array
3) reverse the neg seg given its len
4) reverse the remaining pos seg
compare to your approach mine need an extra step (step 1)
//step 2-3 can be trimmed down to N if using GCD tricks.
I try to apply your sol. on following array
int arr[9] = {-7, -8, 9, -6, -11, -3, -5, 2, 3};
and set
j=0; N = 9;
pos1 = 2; pos2 = 7;
i th
z*********n
发帖数: 1451
22

也放松一下,贴个以前写的编译时间计算int to Roman number的C++ metaprogramming
, 学生时在实验室天天就玩这种东西了:
class R2I {
const static int DIG;
public:
constexpr static char IN[] = "MCDXLVI"; ///This is the INPUT number;
const static int OUT;
};
template struct ID {};
template <> struct ID <'I'> { static const int I = 0; static const int V = 1
; };
template <> struct ID <'V'> { static const int I = 1; static const int V = 5
; };
template <> struct ID <'X'> { static const int I = 2; static const int V =
10... 阅读全帖
H****r
发帖数: 16240
23
来自主题: GunsAndGears版 - Worth the money? Romanian PSL-54C 7.62x54R Rifle
http://www.ar15.com/content/manuals/pos1.pdf
注意第3页,4.2.1 Locking Clamp Adjustment
不过PSL的镜子和枪一起来,卡座松紧程度应该调好了
镜子里的分化,左下角弧线测距用
把1.7米身高的人卡在水平横线和弧线之间,数字是几就是几百米
中心竖着的一堆/\,用最上面那个瞄准。
在一百米打,两个手轮都是拧一格调整瞄准点10cm。弹道手轮往数字大的方向拧会把分
化线往下降,反之往上升;风偏手轮,往红色刻度数字大的方向拧把分化线左移,往黑
色刻度数字大的方向拧,右移。
等到瞄准点和弹着点重合以后,调节轮上中心黑螺丝不能动,拧周围的两个银色螺丝—
—拧松一两圈就行,千万不要拧掉。然后只转调节轮有刻度的银色部分——调里面分化
的实际上只是调节轮面上黑色的盖,被这几个螺丝固定在刻度轮上。所以这时候仅仅动
银色刻度轮的话,里面分化是不动的。
假定校枪的时候无风,那风偏刻度就应该放到0;然后比如是在一百米距离上校的,那
弹道刻度就放到1。
最后再把刚才松掉的几个螺丝适当拧紧,校枪完毕。
以后再打,距离几百米就把弹道手轮调到数字几。
xt
发帖数: 17532
24
来自主题: Science版 - 什么排序法最好?

冒泡法不见得简便啊,下面是merge sort:
Sort(A)
//A: n elements to be sorted
return merge-sort(A, 1, n)
end
merge-sort(A, p, q)
//merge-sort(A, p, q): sort the p-th to q-th elements in A
r = (p+q)/2
if (p=q) return A
else return merge(merge-sort(A, p, r), merge-sort(A, r+1, q))
end
merge(A1, A2)
//precondition: A1, A2 are sorted
n1 = length(A1) //Number of elements in A1
n2 = length(A2) //......................A2
pos1 = 1 //current position in A1
pos2 = 1 //..........
1 (共1页)