Redian新闻
>
大家有么有见过鸡毛菜种子?
avatar
大家有么有见过鸡毛菜种子?# gardening - 拈花惹草
w*x
1
careercup上的一道题:
Imagine you have a square matrix, where each cell is filled with either
black or white. Design an algorithm to find the maximum subsquare such that
all four borders are filled with black pixels.
Assumption: Square is of size NxN.
This algorithm does the following:
1. Iterate through every (full) column from left to right.
2. At each (full) column (call this currentColumn), look at the subcolumns (
from biggest to smallest).
3. At each subcolumn, see if you can form a square with the subcolumn as the
left side. If so, update currentMaxSize and go to the next (full) column.
4. If N - currentColumn <= currentMaxSize, then break completely. We’ve
found the largest square possible. Why? At each column, we’re trying to
create a square with that column as the left side. The largest such square
we could possibly create is N - currentColumn. Thus, if N-currentColumn <=
currentMaxSize, then we have no need to proceed.
Time complexity: O(N^2).
Time complexity: O(N^2).
1 public static Subsquare findSquare(int[][] matrix){
2 assert(matrix.length > 0);
3 for (int row = 0; row < matrix.length; row++){
4 assert(matrix[row].length == matrix.length);
5 }
6
7 int N = matrix.length;
8
9 int currentMaxSize = 0;
10 Subsquare sq = null;
11 int col = 0;
12
13 // Iterate through each column from left to right
14 while (N - col > currentMaxSize) { // See step 4 above
15 for (int row = 0; row < matrix.length; row++){
16 // starting from the biggest
17 int size = N - Math.max(row, col);
18 while (size > currentMaxSize){
19 if (isSquare(matrix, row, col, size)){
20 currentMaxSize = size;
21 sq = new Subsquare(row, col, size);
22 break; // go to next (full) column
23 }
24 size--;
25 }
26 }
27 col++;
28 }
29 return sq;
30 }
31
32 private static boolean isSquare(int[][] matrix, int row, int col,
33 int size) {
34 // Check top and bottom border.
35 for (int j = 0; j < size; j++){
36 if (matrix[row][col+j] == 1) {
37 return false;
38 }
39 if (matrix[row+size-1][col+j] == 1){
40 return false;
41 }
42 }
43
44 // Check left and right border.
45 for (int i = 1; i < size - 1; i++){
46 if (matrix[row+i][col] == 1){
47 return false;
48 }
49 if (matrix[row+i][col+size-1] == 1){
50 return false;
51 }
52 }
53 return true;
54 }
avatar
B*n
2
谢谢
avatar
w*x
3
为什么说是O(n^2), 感觉好像是对的但是证不出来啊
avatar
h*o
4
鸡毛菜的 没见过
买过台湾小白菜的种子, 口感和我老家鸡毛菜很像, 尤其是下汤, 演的比老家的鸡
毛菜浅一点, 也有可能是我种的太密集了 导致颜色不足, 照片里偏黄的那一大堆 下
汤吃 嫩得出水
avatar
c*t
5
不会吧,光第2步,求每个column的subColumn都已经不止O(N^2)了啊

that
(
the

【在 w****x 的大作中提到】
: careercup上的一道题:
: Imagine you have a square matrix, where each cell is filled with either
: black or white. Design an algorithm to find the maximum subsquare such that
: all four borders are filled with black pixels.
: Assumption: Square is of size NxN.
: This algorithm does the following:
: 1. Iterate through every (full) column from left to right.
: 2. At each (full) column (call this currentColumn), look at the subcolumns (
: from biggest to smallest).
: 3. At each subcolumn, see if you can form a square with the subcolumn as the

avatar
g*u
6
好像没见卖鸡毛菜种。可以象hellozero种小白菜,也可以种青菜,未长大的摘了吃,
也挺好,呵呵!

【在 B********n 的大作中提到】
: 谢谢
avatar
w*x
7

可能指的是amortized的复杂度是O(n^2),毕竟当前的max size很大的限制了计算量,
感觉有可能是O(n^2),但是数学功底有限,不知道怎么证明

【在 c********t 的大作中提到】
: 不会吧,光第2步,求每个column的subColumn都已经不止O(N^2)了啊
:
: that
: (
: the

avatar
g*u
8
这两年也常种这种台湾小白菜,是这种淡黄色,熟了颜色偏绿一点。在绿色的菜田中,
有一片这样的小白菜,很别致,有点像花样的感觉,喜欢!
这个春夏秋都能种,倒是不错。现在撒种,天暖长得快,30来天就长大了。

【在 h*******o 的大作中提到】
: 鸡毛菜的 没见过
: 买过台湾小白菜的种子, 口感和我老家鸡毛菜很像, 尤其是下汤, 演的比老家的鸡
: 毛菜浅一点, 也有可能是我种的太密集了 导致颜色不足, 照片里偏黄的那一大堆 下
: 汤吃 嫩得出水

avatar
c*t
9
我是觉得光扫一遍就n^2了,
找subcolumn 相当于找所有subset吧,是n^2 乘以column num = n^3,再每个验证square
,又是n 所以总的是 n^4
他是不是把matrix 元素总数算n啊(不是边长)那就是N^2

【在 w****x 的大作中提到】
:
: 可能指的是amortized的复杂度是O(n^2),毕竟当前的max size很大的限制了计算量,
: 感觉有可能是O(n^2),但是数学功底有限,不知道怎么证明

avatar
B*n
10
哪种哪种?海泰家有么?能帮忙看看是哪种不?
http://www.agrohaitai.com/indexchinese.htm

【在 g***u 的大作中提到】
: 这两年也常种这种台湾小白菜,是这种淡黄色,熟了颜色偏绿一点。在绿色的菜田中,
: 有一片这样的小白菜,很别致,有点像花样的感觉,喜欢!
: 这个春夏秋都能种,倒是不错。现在撒种,天暖长得快,30来天就长大了。

avatar
y*n
11
粗想了一下,这道题应该可以DP, O(n^3)。
不知道有没有更好的方法。
avatar
n*a
12
哪有专门的鸡毛菜种子?小青菜没长大的时就是鸡毛菜。
avatar
g*u
13
种子是在华人超市买的。台湾的农益牌,名字是:台湾小白菜。
前年6月和秋天都撒种在地里。去年3月中旬种,得先室内育苗,搬进搬出晒太阳,天暖
再移栽。由于天冷需要50多天才成熟,费时费力,对我懒人来说,不值。呵呵,勤快人
不要受我影响啊。
现在根据天气和其他菜的间作情况,一年种三次,都直播地里,省事多了。
4月中旬一次,需40来天长大;6月上旬一次,30来天长大;8月底一次,这时天渐冷,
只收获小菜苗。如果有个小棚,可能会好点,秋天想试试。

【在 B********n 的大作中提到】
: 哪种哪种?海泰家有么?能帮忙看看是哪种不?
: http://www.agrohaitai.com/indexchinese.htm

avatar
g*u
14
原来如此,长知识了,呵呵。

【在 n******a 的大作中提到】
: 哪有专门的鸡毛菜种子?小青菜没长大的时就是鸡毛菜。
avatar
d*w
15
我有鸡毛菜种子,但我没有种过,不知长出来是怎样
avatar
z*j
16
鸡毛菜这种菜貌似不同地方品种不同,南方好像把我们北方说的小油菜叫做鸡毛菜。
Anyway,不知鸡毛菜是啥,我当初想找我们北方的小白菜种子(不是大白菜的幼苗,两
个品种),后来在Aliexpress买了这个牌子的,发芽率挺高。
https://www.aliexpress.com/item/Peking-Cabbage-Seed-200-Seeds-Brassica-
campestris-Chinese-Cabbage-Free-Shipping-Common-vegetables-in-Asia/
32804219728.html?spm=2114.search0104.3.198.25ba12a7qE8FuQ&ws_ab_test=
searchweb0_0,searchweb201602_4_10152_10151_10065_10344_10068_10130_10324_
10342_10547_10325_10343_10546_5722611_10340_10548_10341_10545_10696_5722911_
5722811_5722711_10084_10083_10618_10307_10059_100031_10103_10624_10623_10622
_10621_10620_5722511,searchweb201603_11,ppcSwitch_4&algo_expid=d3534621-2b25
-4bcf-af13-228c09ede046-28&algo_pvid=d3534621-2b25-4bcf-af13-228c09ede046&
priceBeautifyAB=0
我自己种出来是长成这样的,嫩的时候蛮好吃的。

【在 B********n 的大作中提到】
: 谢谢
avatar
j*3
17
鸡毛菜就是年青白菜.
不过二三十年前国内物种不那么丰富,说起小白菜就一种,青菜是另外一种.现在一堆有
的没的都敢说自己是小白菜 :)
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。