Redian新闻
>
喵星人“英雄救美”杀退大蛇
avatar
喵星人“英雄救美”杀退大蛇# pets - 心有所宠
b*c
1
sorted matrix = each row/column is sorted
remember k=O(n^2)
write code to solve in n*lg n
----------------------
O(n^2) is simple and stupid --- QuickSelect
avatar
C*y
2
包子不够,paypal 0.35
thanks
avatar
h*a
3
综合成像质量和价格,上哪个镜头比较好?
多谢指教
avatar
C*Y
4
大蛇拦路吓呆柔弱女子 喵星人杀出“英雄救美”
正文
我来说两句(人参与)
扫描到手机
2013年06月14日11:03
来源:中安在线 作者:吴洋
原标题 [大花蛇吓呆女孩突然 喵星人杀出将它斗败(图)]
大蛇逃到一辆车底盘下,惊魂未定的梁小姐这才想起拿手机拍照,可惜不太清楚。(图
片由梁小姐提供)
大蛇逃到一辆车底盘下,惊魂未定的梁小姐这才想起拿手机拍照,可惜不太清楚。
(图片由梁小姐提供)
“要不是那只流浪猫,被咬的可能就是我。”23岁的梁小姐家住省城珠光花园小区
,6月12日23时许,她开车返家,遇到一条近两米长的蛇,吓得迈不开步子。大蛇渐渐
逼近时,一只黑色流浪猫赶来与蛇“斗法”,梁小姐赶紧返回车内报警。10分钟后,警
车驱走了大蛇。不过,梁小姐却失眠了,“窗外的流浪猫叫了好久,可能被蛇咬伤了。”
地上“粗绳”竟是大蛇女孩吓得全身都软了
6月12日23时许,省城马鞍山路珠光花园小区15栋楼,梁小姐把一辆银白色面包车
停在楼下。转身离开时,她发现5米外地面上盘着一条“粗绳子”,仔细一看,“妈呀
,这哪是绳子,分明是条蛇! ”蛇头逐渐抬起,梁小姐想大声尖叫,又不敢叫出声。
大蛇盘踞的地点正对着梁小姐家门口,梁小姐吓得身子都软了。 “蛇有两米长,
黑白相间,差不多拳头般粗细。 ”梁小姐描述,“我最怕蛇了,前晚刚做了个有关蛇
的噩梦,没想到噩梦竟然成真了。 ”梁小姐说,大蛇渐渐逼近,她甚至可以看到蛇吐
出信子。
“喵星人”突然杀出上演“龙虎斗”
令梁小姐没想到的是,紧要关头,一只黑色的猫突然出现在她侧面不远处。 “就
像拍电视剧一样,‘喵星人’接下来的表现让剧情反转了。 ”梁小姐说,“黑猫是只
流浪猫,腹部有一点白色,长得又大又敦实,‘喵喵’几声,还真把大蛇给震住了。 ”
简直就像武侠小说里的情节,开战前,它们先摆了个长长的POSE。梁小姐描述,黑
猫翘起尾巴死盯着大蛇,大蛇蜷成一团看着黑猫,两者相距两米多,相互对视,都不愿
先下手。趁着大蛇分神,梁小姐赶紧躲进车里报了警。
英勇黑猫斗败大蛇见到警车却跑了
一场“蛇猫斗法”上演了。
3分钟后,黑猫终于按捺不住,盯着大蛇往前走了几步,又后退几步,不断张开嘴
巴。见状,大蛇也拿出了它最擅长的姿势:抬头吐信子,脑袋跟着黑猫的身体左右移动。
说时迟那时快,黑猫突然伸出前爪,踩了大蛇腹部一下,又赶紧把身子缩了回去,
后退几步。接下来,黑猫不断使用“降龙十八掌”偷袭大蛇的要害。几个回合下来,大
蛇钻进一辆黑色轿车底盘下,不愿再和黑猫相争,黑猫似乎也丧失了斗志,不愿恋战。
梁小姐用手机拍下了这一幕。
猫和蛇“冷战”几分钟后,辖区民警赶到现场。见到警车赶来,刚才骁勇无比的黑
猫却先跑了。 “黑猫从我们眼前溜走后,我们下车看了一下那辆黑色轿车的底盘,蛇
也爬进草丛里去了。 ”民警说。
物业张贴通知全小区“通缉”大蛇
当晚,梁小姐失眠了,“要没那只流浪猫,被咬的可能就是我。窗外有只猫叫了好
久,是不是它? ”民警走后,她一度壮着胆下楼寻找那只流浪猫,却不见踪影。 “猫
蛇斗”惊心动魄,那条叫不出名的大蛇也让她后怕,尤其是蛇出没在小区健身器材区和
停车场草丛地带,“这些地方人员比较密集,还真是麻烦事。 ”
昨日,记者和梁小姐联系上该小区物业。一名工作人员介绍,小区绿化越来越好,
引来了一些野生动物,小区之前出现过黄鼠狼,但并未出现过蛇。 “我们今晚就会在
小区各栋楼单元门口贴上防范须知,也会加大巡逻力度。 ”
【切记】
遇到蛇变向跑,别走直线!
安徽农业大学动物科学学院张自强副教授专门从事两栖爬行动物学研究。他介绍,
合肥地区常见的毒蛇有短尾蝮、赤练蛇。
一般情况下,蛇常常出没在夏天雨后,如果遇上无毒蛇不必惊慌,只需要慢慢移动
离开即可;如果遇上被毒蛇追逐,最好变向跑动,不要走直线。万一被蛇咬伤,首先要
扎紧伤口,延缓毒素扩散。如果是四肢被咬伤,可用带状物在伤口近心端绑扎,每20分
钟松开一次,以防肢体坏死,并赶紧前往医院。 (吴洋)
avatar
s*m
6
不行吧
邮票都不够cover的

【在 C*****y 的大作中提到】
: 包子不够,paypal 0.35
: thanks

avatar
t*a
7
35/1.8
视角也好点!
avatar
L*u
8
喵主子都是盖世英雄啊~
avatar
T*e
9
啊,最近面世我刚遇到这题。一个印度面世官出的, 你不会和我面得同一家吧?
cupertino的.
avatar
C*y
10
can send the PDF ma ?
avatar
h*a
11
如果主要拍人像呢?

【在 t**a 的大作中提到】
: 35/1.8
: 视角也好点!

avatar
s*u
12
mark,觉得这个题目很有趣,有时间做做
avatar
C*y
13
or the link ?
avatar
x*k
14
35/1.4

【在 h*****a 的大作中提到】
: 如果主要拍人像呢?
avatar
l*a
15
Divid the matrix to 2 by 2. Each are n/2 X n/2
If k<=n*n/4, restrain search to only the top left square
Else if k =>n*n*3/4 restrain search to only the right bottom square
Else restrain search to top right and bottom left square
This way you cut it at least to half size each time
T(n) = 2T(n/2) O(1)
So T(n) = O(nlogn)

O(n) is doable. But I need O(n lgn) and the code.O(n) algorithmhttp://www.cse.yorku.ca/~........

【在 b*****c 的大作中提到】
: O(n) is doable. But I need O(n lgn) and the code.
: O(n) algorithm
: http://www.cse.yorku.ca/~andy/pubs/X+Y.pdf

avatar
l*w
16
yan22 有
avatar
d*0
17
85/1.4D,价格便宜量又足
avatar
T*e
18
Are you sure it's working? For example,
Find the 4th element in 6x6 matrix.
matrix:
1 20 30 40 50 60
2 21 31 41 51 61
3 22 32 42 52 62
4 23 33 43 53 63
5 24 34 44 54 64
6 25 35 45 55 65

【在 l******a 的大作中提到】
: Divid the matrix to 2 by 2. Each are n/2 X n/2
: If k<=n*n/4, restrain search to only the top left square
: Else if k =>n*n*3/4 restrain search to only the right bottom square
: Else restrain search to top right and bottom left square
: This way you cut it at least to half size each time
: T(n) = 2T(n/2) O(1)
: So T(n) = O(nlogn)
:
: O(n) is doable. But I need O(n lgn) and the code.O(n) algorithmhttp://www.cse.yorku.ca/~........

avatar
l*a
19
同求一个,paypal
avatar
b*s
20
换D700

【在 h*****a 的大作中提到】
: 综合成像质量和价格,上哪个镜头比较好?
: 多谢指教

avatar
b*c
21
樓上的,
1 1 1 1
1 2 2 2
1 2 2 2
1 2 2 2
找k=4,你的算法錯了,不能只看topleft
avatar
n*e
22
同求一个,楼上优先。
avatar
x*k
23
眼泪哗哗的

【在 b*******s 的大作中提到】
: 换D700
avatar
b*c
24
1) O(k*log(min(k,n)) , just look at my original thread, k=O(n^2) !!!!
Quickselect = O(n^2). O(k*log(min(k,n)) will be "Stupider"
2) O((n+n)*log(range of values in matrix)
tell me how do you solve
1 2 3 99999
1 2 3 99999
1 2 3 99999
1 2 3 99999
k=5

of
the

【在 T*******e 的大作中提到】
: Are you sure it's working? For example,
: Find the 4th element in 6x6 matrix.
: matrix:
: 1 20 30 40 50 60
: 2 21 31 41 51 61
: 3 22 32 42 52 62
: 4 23 33 43 53 63
: 5 24 34 44 54 64
: 6 25 35 45 55 65

avatar
C*y
25
已经求到,谢谢
avatar
h*a
26
钱不够啊

【在 b*******s 的大作中提到】
: 换D700
avatar
T*e
27
I didn't say they were better than O(n^2). I just say they
are two methods that I can think of.
avatar
AE
28
co-qiu one

同求一个,楼上优先。

【在 n*****e 的大作中提到】
: 同求一个,楼上优先。
avatar
x*k
29
涨价了

【在 h*****a 的大作中提到】
: 钱不够啊
avatar
l*a
30
Here is another try:
Sp=0;
Ep=n-1;
While (sp{
mid=(sp ep)/2;
Pick m[mid][mid],
walk up and right to find last column index on each row( above row mid) that
is less than m[mid][mid]
Then walk down and left to find last column index on each row( below row mid
) that is less than m[mid][mid]
Now you have separate the whole data set to 2 data set in 2n time
If first set count>k, ep=mid;
Else{ sp= mid 1;k-=count of set 1;}
}
So loop logn time! you will find the final mid associate with 2n elements,
you can find the kth element from these 2n element
avatar
y*0
31
也求一个,多谢~

【在 n*****e 的大作中提到】
: 同求一个,楼上优先。
avatar
h*a
32
形势严峻啊

【在 x***k 的大作中提到】
: 涨价了
avatar
b*c
33
good job. running simulation to verify

that
mid

【在 l******a 的大作中提到】
: Here is another try:
: Sp=0;
: Ep=n-1;
: While (sp: {
: mid=(sp ep)/2;
: Pick m[mid][mid],
: walk up and right to find last column index on each row( above row mid) that
: is less than m[mid][mid]
: Then walk down and left to find last column index on each row( below row mid

avatar
h*t
34
同求,多谢!

【在 y*****0 的大作中提到】
: 也求一个,多谢~
avatar
b*s
35
前一段二手1600其实不错了

【在 h*****a 的大作中提到】
: 钱不够啊
avatar
b*c
36
lol.
1 2 4
2 3 4
2 4 4
k=5就错了

【在 s******u 的大作中提到】
: mark,觉得这个题目很有趣,有时间做做
avatar
x*3
37


【在 t**a 的大作中提到】
: 35/1.8
: 视角也好点!

avatar
s*k
38
kth element难道不是matrix[k/n][k%n-1]?
avatar
b*c
39
是每行每列分别有序,不是将matrix视作array的有序,
前者是sorted matrix的数学定义,后者是不知出处的定义

【在 s********k 的大作中提到】
: kth element难道不是matrix[k/n][k%n-1]?
avatar
s*k
40
找 kth 最小 element?

【在 b*****c 的大作中提到】
: 是每行每列分别有序,不是将matrix视作array的有序,
: 前者是sorted matrix的数学定义,后者是不知出处的定义

avatar
b*c
41
不过最小是不表意的,因为kth最小和kth最大两种说法是同一意思。

【在 s********k 的大作中提到】
: 找 kth 最小 element?
avatar
T*e
42

you can verify it yourself or just lol. What do I care.

【在 b*****c 的大作中提到】
: 不过最小是不表意的,因为kth最小和kth最大两种说法是同一意思。
avatar
b*c
43
是看不懂你的过程,叫你用这个简单例子讲

【在 T*******e 的大作中提到】
:
: you can verify it yourself or just lol. What do I care.

avatar
b*c
44
bump
avatar
D*d
45
每次把矩阵划成4份,每次至少能够扔掉1/4,也就是说如果k>左上角的最大值,那么扔
掉左上角,如果kT(n) = 3*T(1/4n)+a?然后复杂度是多少?有点蒙。。
avatar
j*8
46
//Best first search, time complexity O(klog(n)). The size of heap is at most
2*n. Every time an element is popped from the heap or inserted to the heap,
O(log(n)). We need to do the pop and insert operations k times. So the time
complexity is O(klog(n)).
//Space complexity O(n), because there are at most 2*n nodes in the priority
queue.
struct node
{
int index;
int val;
node(int index_, int val_): index(index_), val(val_){}
bool operator > (const node& other) const
{
return val > other.val;
}
};
static int findKthSmallest2D(const vector> &mat, int k)
{
int res = INT_MIN;
int m = mat.size();
if (m == 0)
{
return res;
}
int n = mat[0].size();
if (n == 0)
{
return res;
}
priority_queue, greater> minHeap;
unordered_set hash; // to avoid duplication.
minHeap.push(node(0, mat[0][0]));
hash.insert(0);
while (!minHeap.empty())
{
node top = minHeap.top();
minHeap.pop();
k--;
if (k == 0)
{
return top.val;
}
int i = top.index / n;
int j = top.index % n;
int c1 = (i + 1) * n + j;
int c2 = i * n + j + 1;
if (i + 1 < m && hash.find(c1) == hash.end())
{
minHeap.push(node(c1, mat[i + 1][j]));
hash.insert(c1);
}
if (j + 1 < n && hash.find(c2) == hash.end())
{
minHeap.push(node(c2, mat[i][j + 1]));
hash.insert(c2);
}
}
return res;
}
avatar
W*y
47
从右上开始找,
若大于input,move down
若小于input,move left,
若等于input, return
一直找到左壁或者下壁。ruturn false.
这样扫 2*n个元素必能找到,
avatar
b*g
48
哪里有input?.....这是看成leetcode上那道了?....

【在 W*********y 的大作中提到】
: 从右上开始找,
: 若大于input,move down
: 若小于input,move left,
: 若等于input, return
: 一直找到左壁或者下壁。ruturn false.
: 这样扫 2*n个元素必能找到,

avatar
b*c
50
sorted matrix = each row/column is sorted
e.g.,
1 6 6
2 7 7
2 8 9
k=7
remember k=O(n^2)
write code to solve in n*lg n
----------------------
O(n^2) is simple and stupid --- QuickSelect!!!!!!!!
avatar
T*e
52
啊,最近面世我刚遇到这题。一个印度面世官出的, 你不会和我面得同一家吧?
cupertino的.
avatar
s*u
53
mark,觉得这个题目很有趣,有时间做做
avatar
l*a
54
Divid the matrix to 2 by 2. Each are n/2 X n/2
If k<=n*n/4, restrain search to only the top left square
Else if k =>n*n*3/4 restrain search to only the right bottom square
Else restrain search to top right and bottom left square
This way you cut it at least to half size each time
T(n) = 2T(n/2) O(1)
So T(n) = O(nlogn)

O(n) is doable. But I need O(n lgn) and the code.O(n) algorithmhttp://www.cse.yorku.ca/~........

【在 b*****c 的大作中提到】
: O(n) is doable. But I need O(n lgn) and the code.
: O(n) algorithm
: http://www.cse.yorku.ca/~andy/pubs/X+Y.pdf

avatar
T*e
55
Are you sure it's working? For example,
Find the 4th element in 6x6 matrix.
matrix:
1 20 30 40 50 60
2 21 31 41 51 61
3 22 32 42 52 62
4 23 33 43 53 63
5 24 34 44 54 64
6 25 35 45 55 65

【在 l******a 的大作中提到】
: Divid the matrix to 2 by 2. Each are n/2 X n/2
: If k<=n*n/4, restrain search to only the top left square
: Else if k =>n*n*3/4 restrain search to only the right bottom square
: Else restrain search to top right and bottom left square
: This way you cut it at least to half size each time
: T(n) = 2T(n/2) O(1)
: So T(n) = O(nlogn)
:
: O(n) is doable. But I need O(n lgn) and the code.O(n) algorithmhttp://www.cse.yorku.ca/~........

avatar
b*c
56
樓上的,
1 1 1 1
1 2 2 2
1 2 2 2
1 2 2 2
找k=4,你的算法錯了,不能只看topleft
avatar
b*c
57
1) O(k*log(min(k,n)) , just look at my original thread, k=O(n^2) !!!!
Quickselect = O(n^2). O(k*log(min(k,n)) will be "Stupider"
2) O((n+n)*log(range of values in matrix)
tell me how do you solve
1 2 3 99999
1 2 3 99999
1 2 3 99999
1 2 3 99999
k=5

of
the

【在 T*******e 的大作中提到】
: Are you sure it's working? For example,
: Find the 4th element in 6x6 matrix.
: matrix:
: 1 20 30 40 50 60
: 2 21 31 41 51 61
: 3 22 32 42 52 62
: 4 23 33 43 53 63
: 5 24 34 44 54 64
: 6 25 35 45 55 65

avatar
T*e
58
I didn't say they were better than O(n^2). I just say they
are two methods that I can think of.
avatar
l*a
59
Here is another try:
Sp=0;
Ep=n-1;
While (sp{
mid=(sp ep)/2;
Pick m[mid][mid],
walk up and right to find last column index on each row( above row mid) that
is less than m[mid][mid]
Then walk down and left to find last column index on each row( below row mid
) that is less than m[mid][mid]
Now you have separate the whole data set to 2 data set in 2n time
If first set count>k, ep=mid;
Else{ sp= mid 1;k-=count of set 1;}
}
So loop logn time! you will find the final mid associate with 2n elements,
you can find the kth element from these 2n element
avatar
b*c
60
good job. running simulation to verify

that
mid

【在 l******a 的大作中提到】
: Here is another try:
: Sp=0;
: Ep=n-1;
: While (sp: {
: mid=(sp ep)/2;
: Pick m[mid][mid],
: walk up and right to find last column index on each row( above row mid) that
: is less than m[mid][mid]
: Then walk down and left to find last column index on each row( below row mid

avatar
b*c
61
lol.
1 2 4
2 3 4
2 4 4
k=5就错了

【在 s******u 的大作中提到】
: mark,觉得这个题目很有趣,有时间做做
avatar
s*k
62
kth element难道不是matrix[k/n][k%n-1]?
avatar
b*c
63
是每行每列分别有序,不是将matrix视作array的有序,
前者是sorted matrix的数学定义,后者是不知出处的定义

【在 s********k 的大作中提到】
: kth element难道不是matrix[k/n][k%n-1]?
avatar
s*k
64
找 kth 最小 element?

【在 b*****c 的大作中提到】
: 是每行每列分别有序,不是将matrix视作array的有序,
: 前者是sorted matrix的数学定义,后者是不知出处的定义

avatar
b*c
65
不过最小是不表意的,因为kth最小和kth最大两种说法是同一意思。

【在 s********k 的大作中提到】
: 找 kth 最小 element?
avatar
T*e
66

you can verify it yourself or just lol. What do I care.

【在 b*****c 的大作中提到】
: 不过最小是不表意的,因为kth最小和kth最大两种说法是同一意思。
avatar
b*c
67
是看不懂你的过程,叫你用这个简单例子讲

【在 T*******e 的大作中提到】
:
: you can verify it yourself or just lol. What do I care.

avatar
b*c
68
bump
avatar
D*d
69
每次把矩阵划成4份,每次至少能够扔掉1/4,也就是说如果k>左上角的最大值,那么扔
掉左上角,如果kT(n) = 3*T(1/4n)+a?然后复杂度是多少?有点蒙。。
avatar
j*8
70
//Best first search, time complexity O(klog(n)). The size of heap is at most
2*n. Every time an element is popped from the heap or inserted to the heap,
O(log(n)). We need to do the pop and insert operations k times. So the time
complexity is O(klog(n)).
//Space complexity O(n), because there are at most 2*n nodes in the priority
queue.
struct node
{
int index;
int val;
node(int index_, int val_): index(index_), val(val_){}
bool operator > (const node& other) const
{
return val > other.val;
}
};
static int findKthSmallest2D(const vector> &mat, int k)
{
int res = INT_MIN;
int m = mat.size();
if (m == 0)
{
return res;
}
int n = mat[0].size();
if (n == 0)
{
return res;
}
priority_queue, greater> minHeap;
unordered_set hash; // to avoid duplication.
minHeap.push(node(0, mat[0][0]));
hash.insert(0);
while (!minHeap.empty())
{
node top = minHeap.top();
minHeap.pop();
k--;
if (k == 0)
{
return top.val;
}
int i = top.index / n;
int j = top.index % n;
int c1 = (i + 1) * n + j;
int c2 = i * n + j + 1;
if (i + 1 < m && hash.find(c1) == hash.end())
{
minHeap.push(node(c1, mat[i + 1][j]));
hash.insert(c1);
}
if (j + 1 < n && hash.find(c2) == hash.end())
{
minHeap.push(node(c2, mat[i][j + 1]));
hash.insert(c2);
}
}
return res;
}
avatar
W*y
71
从右上开始找,
若大于input,move down
若小于input,move left,
若等于input, return
一直找到左壁或者下壁。ruturn false.
这样扫 2*n个元素必能找到,
avatar
b*g
72
哪里有input?.....这是看成leetcode上那道了?....

【在 W*********y 的大作中提到】
: 从右上开始找,
: 若大于input,move down
: 若小于input,move left,
: 若等于input, return
: 一直找到左壁或者下壁。ruturn false.
: 这样扫 2*n个元素必能找到,

avatar
b*c
74
不是说了k=o(n^2)吗,晕死
o(n*lgn)基本没戏了,看能不能数学证明下这是不可能的
avatar
h*r
75
请问能不能说明下quick select怎么做这题?多谢

【在 b*****c 的大作中提到】
: 不是说了k=o(n^2)吗,晕死
: o(n*lgn)基本没戏了,看能不能数学证明下这是不可能的

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