# 我的窗户上有水

13

## 输入值

``````// 2-dimensional:
[[0,1,0,0,0,0,1,0,0,0],
[0,1,1,0,0,0,0,1,1,0],
[0,1,1,0,0,0,0,1,0,0],
[0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0],
[0,0,0,1,1,0,0,0,1,0],
[0,0,0,1,1,0,0,0,1,0],
[0,0,0,0,0,1,1,0,1,0],
[0,0,0,0,0,1,1,0,1,0],
[0,0,0,0,0,0,0,0,0,0]]

// 1-dimensional
[0,1,0,0,0,0,1,0,0,0,
0,1,1,0,0,0,0,1,1,0,
0,1,1,0,0,0,0,1,0,0,
0,1,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,1,0,
0,0,0,1,1,0,0,0,1,0,
0,0,0,1,1,0,0,0,1,0,
0,0,0,0,0,1,1,0,1,0,
0,0,0,0,0,1,1,0,1,0,
0,0,0,0,0,0,0,0,0,0]
``````

## 输出量

“大小：Z坐标：（X1，Y1）（X2，Y2）..” 的格式输出最大连接区域的大小以及属于该区域的水滴的x坐标和y坐标。 ”。

``````Size: 6 Coordinates: (1,0) (1,1) (2,1) (1,2) (2,2) (1,3)
``````

## 规则

• 如果水滴相互垂直接触，则它们相互连接
• 对角线连接不计算在内
• 可能有很多领域，您的代码必须找到最大的领域
• 空字段表示为“ 0”，湿字段表示为“ 1”
• 发布您的解决方案并提供简短说明和先前输入的输出
• 接下来7天内的最短代码将获胜
• 如果有两个面积相同的区域，则可以选择一个

### 优胜者：Ventero 171-红宝石

2
@Doorknob抱怨打字错误？OP是德语。
edc65

1
@Doorknob我更改了，谢谢。时限仅说明我何时确定获胜者，但您仍然可以发布答案。

6
2014年

1
2014年

2

Ventero 2014年

3

## Ruby，171个字符

``````r=eval *\$*
u=(0..99).map(&v=->p{-~p*r[p]>0?" (#{r[p]=0;u=p%c=10},#{p/c})"+v[p+c]+v[p-c]+v[u>0?p-1:p]+v[u<9?p+1:p]:""}).max_by &:size
puts"Size: #{u.size/6} Coordinates:"+u
``````

5

# Python-192

``````a=10;g+=[0]*a
def f(k):
if g[k]:g[k]=0;return" (%d,%d)"%(k/a,k%a)+f(k+a)+f(k-a)+f(k+(k%a<9))+f(k-(k%a>0))
return''
m=max(map(f,range(100)),key=len)
print"Size: "+`len(m)/6`+" Coordinates:"+m``````

``````g=[0,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0]
``````

3

# C＃-548 523 522 511 503 476

（500 ...以下）

``````using o=System.Console;using l=System.Collections.Generic.List<int[]>;class P{
static int[,] a ={{0,1,0,0,0,0,1,0,0,0},{0,1,1,0,0,0,0,1,1,0},{0,1,1,0,0,0,0,1,0,0},{0,1,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,1,0},{0,0,0,1,1,0,0,0,1,0},{0,0,0,1,1,0,0,0,1,0},{0,0,0,0,0,1,1,0,1,0},{0,0,0,0,0,1,1,0,1,0},{0,0,0,0,0,0,0,0,0,0}};
static int w=10,h=w,x=0,y;static l t=new l(),m=new l();static void f(int r,int c){if(a[r,c]==1){a[r,c]=0;if(r<h)f(c,r+1);if(r>0)f(c,r-1);if(c<w)f(c+1,r);if(c>0)f(c-1,r);t.Add(new[]{c,r});}}static void Main(){for(;++x<w;)for(y=0;++y<h;){if(a[x,y]==1)f(x,y);if(t.Count>m.Count)m=t.FindAll(r=>true);t.Clear();}o.Write("Size: "+m.Count+" Coordinates: ");m.ForEach(c=>o.Write("({0},{1}) ",c[0],c[1]));}}
``````

3

# Mathematica-180个字节

### 打高尔夫球

``````f@x_:=(c=MorphologicalComponents[x,CornerNeighbors->False];m=Last@SortBy[ComponentMeasurements[c,"Count"],Last];Print["Size: ",Last@m," Coordinates: ",Reverse/@Position[c,m[[1]]]])
``````

### 漂亮

``````f@x_ := (
c = MorphologicalComponents[x, CornerNeighbors -> False];
m = Last@SortBy[ComponentMeasurements[c, "Count"], Last];
Print["Size: ", Last@m, " Coordinates: ", Reverse/@Position[c, m[[1]]]]
);
``````

### 例

``````{0,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0};
w=Partition[%,10];
f@w
``````

### 说明

`f`是的功能`x`。它定义`c`为的变换`x`，其中每个（i，j）现在等于一个整数，该整数对应于它属于哪个连接的组件。它涉及主要工作：

``````MorphologicalComponents[w, CornerNeighbors -> False] // Colorize
``````

2

# 哈斯克尔（246）

``````r=[0..9]
q=[(i,j)|i<-r,j<-r]
t v p@(i,j)|elem p v||notElem p q||g!!j!!i==0=v|1<2=foldr(\(k,l)v->t v(i+k,j+l))(p:v)\$zip[-1,0,1,0][0,-1,0,1]
(?)=map
a=t[]?q;(b,c)=maximum\$zip(length?a)a
main=putStrLn.unwords\$["Size:",show b,"Coordinates:"]++show?c
``````

## 输入值

``````g = [[0, 1, 1, ......, 0], [......], ....]
``````

## 不打高尔夫球

``````field = [
[0,1,0,0,0,0,1,0,0,0],
[0,1,1,0,0,0,0,1,1,0],
[0,1,1,0,0,0,0,1,0,0],
[0,1,0,0,0,0,0,0,0,0],
[0,0,0,0,0,0,0,0,1,0],
[0,0,0,1,1,0,0,0,1,0],
[0,0,0,1,1,0,0,0,1,0],
[0,0,0,0,0,1,1,0,1,0],
[0,0,0,0,0,1,1,0,1,0],
[0,0,0,0,0,0,0,0,0,0]
]
range = [0..9]
positions = [(i, j) | i <- range, j <- range]
directions = zip [-1, 0, 1, 0] [0, -1, 0, 1]
traverse visited pos@(i, j)
| pos `elem` visited || pos `notElem` positions || field!!j!!i == 0 = visited
| otherwise = foldr folder (pos:visited) directions
where folder = (\(di, dj) visited -> traverse visited (i + di, j + dj))
blocks = map (traverse []) positions
(maxCount, maxBlock) = maximum \$ zip (map length blocks) blocks
main = putStrLn.unwords \$ ["Size:", show maxCount, "Coordinates:"] ++ map show maxBlock
``````

2

### C＃374byte函数

``static string F(int[]g){int s=10,e=0,d=s*s,a=0,b=d+1;int[]t=new int[b],r=new int[b];t[d]=d;System.Func<int,int>T=null,k=v=>t[T(v)]=t[v]<d?a:d;T=v=>t[v]!=v?T(t[v]):v;for(;a<d;a++)if(g[a]>0){e=t[a]=a;if(a>s)k(a-s);if(a%s>0)k(a-1);}else t[a]=d;for(;a-->0;)e=r[e]<++r[b=T(a)]&&b<d?b:e;var p="Size: "+r[e]+" Coordinates:";for(;d-->1;)p+=T(d)==e?" ("+d%s+","+d/s+")":"";return p;}``

``````class P
{
static int[] z = {0,1,0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,1,1,0,0,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0};

static string F(int[]g)
{
int s=10,e=0,d=s*s,a=0,b=d+1;

int[]t=new int[b],r=new int[b];
t[d]=d;
System.Func<int,int>T=null,k=v=>t[T(v)]=t[v]<d?a:d;
T=v=>t[v]!=v?T(t[v]):v;

for(;a<d;a++)
if(g[a]>0)
{
e=t[a]=a;
if(a>s)k(a-s);
if(a%s>0)k(a-1);
}
else
t[a]=d;
for(;a-->0;)
e=r[e]<++r[b=T(a)]&&b<d?b:e;

var p="Size: "+r[e]+" Coordinates:";
for(;d-->1;)
p+=T(d)==e?" ("+d%s+","+d/s+")":"";

return p;
}

static void Main()
{
System.Console.WriteLine(F(z));
}
}``````

1

# 的JavaScript（EcmaScript的6）183 189

``````W=(a,n=10,x=0)=>(F=p=>a[p]|0&&(a[p]=0,o+=' ('+p%n+','+(p/n|0)+')',1+F(p-n)+F(p+n)+F(p-(p%n>0))+F(p+((p+1)%n>0))),a.map((e,p)=>(t=F(p,o=''))>x&&(x=t,k=o)),'Size: '+x+' Coordinates:'+k)
``````

``````Size: 6 Coordinates: (1,0) (1,1) (1,2) (1,3) (2,2) (2,1)
``````

``````W=(a,n=10,x=0)=>
(
F=p=>
a[p]|0&&(
a[p]=0,o+=' ('+p%n+','+(p/n|0)+')',
1+F(p-n)+F(p+n)+F(p-(p%n>0))+F(p+((p+1)%n>0)) // modulo takes care of not overflowing out of a row
),
a.map((e,p)=>(t=F(p,o=''))>x&&(x=t,k=o)),
'Size: '+x+' Coordinates:'+k
)
``````

`````` For each element,
try to fill.
During the fill operation build a string with the coordiinates.
Remember the longest fill and the corresponding string and
output that at the end.
``````

1

## JavaScript 273

``````function G(m){var B="",b=0;for(var p=0;p<m.length;p++)if(m[p]){var T="",t=0;
Z(p);if(t>b){b=t;B=T;}}return"Size: "+b+" Coordinates:"+B;function Z(p){if(m[p])
{m[p]=0;t++;T+=" ("+p%10+","+Math.floor(p/10)+")";if(p>9)Z(p-10);if(p%10)Z(p-
1);if(p<90)Z(p+10);if(p%10!=9)Z(p+1);}}}``````

``````var map = [0, 1, 0, 0, 0, 0, 1, 0, 0, 0,
...
0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

function F(map) {

var bestBlob = "", bestLen=0;
for (var p = 0; p < map.length; p++)
if (map[p]) {
var thisBlob = "", thisLen=0;
Fill(p);
if (thisLen > bestLen){
bestLen=thisLen ; bestBlob = thisBlob;
}
}
return "Size: " + bestLen + " Coordinates:" + bestBlob;

function Fill(p) {
if (map[p]) {
map[p] = 0; thisLen++;
thisBlob += " (" + p % 10 + "," + Math.floor(p / 10) + ")";
if (p > 9) Fill(p - 10);
if (p % 10) Fill(p - 1);
if (p < 90) Fill(p + 10);
if (p % 10 != 9) Fill(p + 1);
}
}
}``````

1

# 斯卡拉420

``````val o=for{(r, y)<-w.zipWithIndex;(v,x)<-r.zipWithIndex;if(v == 1)}yield(x,y);val a=o.flatMap(c=>o.collect{case(x,y)if{(x==c._1+1||x==c._1-1)&&y==c._2^(y==c._2+1||y==c._2-1)&&x==c._1}=>c->(x,y)}).groupBy(_._1).map(n => (n._1->n._2.map(t=>t._2)));val b=a.values.flatMap(v=>v.map(c=>a(c)++v));val l=b.collect{case x if (x.length==b.map(_.length).max)=>x}.head;println(s\"Size: \${l.length} Coordinates: \${l.mkString(" ")}\")
``````

## 更易读

`````` val w = {
List(//0,1,2,3,4,5,6,7,8,9
List(0,1,0,0,0,0,1,0,0,0), //0
List(0,1,1,0,0,0,0,1,1,0), //1
List(0,1,1,0,0,0,0,1,0,0), //2
List(0,1,0,0,0,0,0,0,0,0), //3
List(0,0,0,0,0,0,0,0,1,0), //4
List(0,0,0,1,1,0,0,0,1,0), //5
List(0,0,0,1,1,0,0,0,1,0), //6
List(0,0,0,0,0,1,1,0,1,0), //7
List(0,0,0,0,0,1,1,0,1,0), //8
List(0,0,0,0,0,0,0,0,0,0)) //9
}

case class Coord(x: Int, y: Int)

val ones: List[Coord] = for{
(row, y)   <- w.zipWithIndex
(value, x) <- row.zipWithIndex
if (value == 1)
} yield Coord(x,y)

val adjacencyMap: Map[Coord, List[Coord]] = ones.flatMap(keyCoord => ones.collect{