# 确定乔木满意的点集

14

``````......
....O.
......
.O....
......
``````

``````......
....O.
......
.O..O.
......
``````

## 挑战

• 您可以选择使用这些字符，`O``.`与任何其他可打印的ASCII字符对互换。只需指定程序使用哪个字符映射即可。
• 网格将始终为矩形。尾随换行符是允许的。

## 更多例子

``````.OOO.
OO...
.O.OO
.O..O
....O

..O..
OOOO.
...O.
.O.O.
...OO

O.O.
..O.
OOOO
.O.O
OO..

...
...
...

...
..O
...

O.....
O.O..O
.....O

OOO.OO
``````

``````..O..
O....
...O.
.O...
....O

..O..
O.OO.
...O.
.O.O.
...OO

O.....
..O...
.....O
``````

1

Denker

feersum '16

7

# 蜗牛，29 30 39字节

``````!{t\Oo\.+c\.,\O!{t\O{w!(.,~}2
``````

3

# 甲骨文的SQL 11.2 364个 344字节

``````WITH v AS(SELECT MOD(LEVEL-1,:w)x,FLOOR((LEVEL-1)/:w)y FROM DUAL WHERE'O'=SUBSTR(:g,LEVEL,1)CONNECT BY LEVEL<=LENGTH(:g))SELECT a.*,b.*FROM v a,v b WHERE b.x>a.x AND b.y>a.y MINUS SELECT a.*,b.*FROM v a,v b,v c WHERE((c.x IN(a.x,b.x)AND c.y>=a.y AND c.y<=b.y)OR(c.y IN(a.y,b.y)AND c.x>=a.x AND c.x<=b.x))AND(c.x,c.y)NOT IN((a.x,a.y),(b.x,b.y));
``````

：g是作为字符串的网格
：w是网格的宽度

``````WITH v AS
(
SELECT MOD(LEVEL-1,:w)x,FLOOR((LEVEL-1)/:w)y,SUBSTR(:g,LEVEL,1)p
FROM   DUAL
WHERE  'O'=SUBSTR(:g,LEVEL,1)
CONNECT BY LEVEL<=LENGTH(:g)
)
SELECT a.*,b.*FROM v a,v b
WHERE b.x>a.x AND b.y>a.y
MINUS
SELECT a.*,b.*FROM v a,v b,v c
WHERE((c.x IN(a.x,b.x) AND c.y>=a.y AND c.y<=b.y) OR (c.y IN(a.y,b.y) AND c.x>=a.x AND c.x<=b.x))
AND(c.x,c.y)NOT IN((a.x,a.y),(b.x,b.y));
``````

where子句的最后一部分确保了第三点不是定义矩形的两个点之一。

2

# MATL，38字节

``````Ti2\2#fh!XJ"J@-XKtAZ)"@K-@/Eq|1>~As2>*
``````

``````['......';'....O.';'......';'.O..O.';'......']
``````

• 乔装满意：

``````['.OOO.';'OO...';'.O.OO';'.O..O';'....O']
['..O..';'OOOO.';'...O.';'.O.O.';'...OO']
['O.O.';'..O.';'OOOO';'.O.O';'OO..']
['...';'...';'...']
['...';'..O';'...']
['O.....';'O.O..O';'.....O']
['OOO.OO']
``````
• 不满意：

``````['..O..';'O....','...O.';'.O...';'....O']
['..O..';'O.OO.';'...O.';'.O.O.';'...OO']
['O.....';'..O...';'.....O']
``````

### 说明

``````T          % push "true"
i          % take input 2D array
2\         % modulo 2: gives 1 for 'O', 0 for '.'
2#f        % row and column coordinates of ones. Gives two column arrays
h!         % concatenate horizontally. Transpose. Each point is a column
XJ         % copy to clipboard J
"          % for each column
J        %   push all points
@-       %   subtract current point (move to origin)
XK       %   copy to clipboard K
tA       %   logical index of points whose two coordinates are non-zero
Z)       %   keep only those points. Each is a column
"        %   for each column (point)
@K-    %     push that point. Subtract all others
@/     %     divide by current point
Eq|1>~ %     true if in the interval [0,1]
A      %     true if that happens for the two coordinates
s      %     sum: find out how many points fulfill that
2>     %     true if that number is at least 3
*      %     multiply (logical and). (There's an initial true value at the bottom)
%   end
% end
% implicit display
``````

Denker

@DenkerAffe :-)好吧，我回到了真实姓名。另一个很有趣，但是它只是临时的
Luis Mendo

1

Denker

@DenkerAffe我将来可能会使用该名称或其他名称。牛仔灵魂怎么样？:-D
Luis Mendo

1
...而且您也必须等待30天（我想）
Stewie Griffin

2

# PHP，1123字节，851字节，657字节

（新手php）

``````<?php
\$B=array_map("str_split",array_map("trim",file('F')));\$a=[];\$b=-1;foreach(\$B as \$c=>\$C){foreach(\$C as \$d=>\$Z){if(\$Z=='O'){\$a[++\$b][]=\$c;\$a[\$b][]=\$d;}}}\$e=array();foreach(\$a as \$f=>\$l){foreach(\$a as \$g=>\$m){\$h=\$l[0];\$i=\$l[1];\$j=\$m[0];\$k=\$m[1];if(\$h!=\$j&&\$i!=\$k&&!(in_array([\$g,\$f],\$e,1)))\$e[]=[\$f,\$g];}}\$A=array();foreach(\$e as \$E){\$n=\$E[0];\$o=\$E[1];\$q=\$a[\$n][0];\$s=\$a[\$n][1];\$r=\$a[\$o][0];\$t=\$a[\$o][1];\$u=(\$q<\$r)?\$q:\$r;\$v=(\$s<\$t)?\$s:\$t;\$w=(\$q>\$r)?\$q:\$r;\$X=(\$s>\$t)?\$s:\$t;\$Y=0;foreach(\$a as \$p){\$x=\$p[0];\$y=\$p[1];if(\$x>=\$u&&\$x<=\$w&&\$y>=\$v&&\$y<=\$X){\$Y=(\$x==\$q&&\$y==\$s)||(\$x==\$r&&\$y==\$t)?0:1;}if(\$Y==1)break;}if(\$Y==1)\$A[]=1;}echo count(\$A)==count(\$e)?1:0;
``````

``````<?php
\$lines=array_map("str_split",array_map("trim",file('F'))); // grid in file 'F'

//saving coords
\$coords=[]; // new array
\$iCoord=-1;
foreach(\$lines as \$rowIndex=>\$line) {
foreach(\$line as \$colIndex=>\$value) {
if (\$value=='O'){
\$coords[++\$iCoord][]=\$rowIndex;//0 is x
\$coords[\$iCoord][]=\$colIndex;  //1 is y
}
}
}

/* for each point, draw as many rectangles as other points
* without creating 'mirror' rectangles
*/
\$rectangles=array();

foreach (\$coords as \$point1Index=>\$point1) {
//draw
foreach (\$coords as \$point2Index=>\$point2) {
\$point1X=\$point1[0];
\$point1Y=\$point1[1];
\$point2X=\$point2[0];
\$point2Y=\$point2[1];
//if not on the same line or on the same column, ...
if (\$point1X!=\$point2X &&   // same line
\$point1Y!=\$point2Y &&   // same column
!(in_array([\$point2Index,\$point1Index],\$rectangles,true)) //... and if no 'mirror one' already
) \$rectangles[]=[\$point1Index,\$point2Index]; //create a new rectangle
}
}

//now that we have rectangles and coords
//try and put a third point into each
\$tests=array();
foreach (\$rectangles as \$rectangle) {
\$pointA=\$rectangle[0];    // points of the rectangle
\$pointB=\$rectangle[1];    // __________"____________
\$xA=\$coords[\$pointA][0];
\$yA=\$coords[\$pointA][1];
\$xB=\$coords[\$pointB][0];
\$yB=\$coords[\$pointB][1];
\$minX=(\$xA<\$xB)?\$xA:\$xB;
\$minY=(\$yA<\$yB)?\$yA:\$yB;
\$maxX=(\$xA>\$xB)?\$xA:\$xB;
\$maxY=(\$yA>\$yB)?\$yA:\$yB;

\$arborally=false;
foreach (\$coords as \$point) {
\$x=\$point[0];
\$y=\$point[1];
if (\$x>=\$minX &&
\$x<=\$maxX &&
\$y>=\$minY &&
\$y<=\$maxY) {
\$arborally=(\$x==\$xA&&\$y==\$yA) || (\$x==\$xB&&\$y==\$yB)?0:1; //same point (pointA or pointB)
}
if (\$arborally==true) break;//1 found, check next rectangle
}
if (\$arborally==true) \$tests[]=1;//array of successes

}

echo count(\$tests)==count(\$rectangles)?1:0; //if as many successes than rectangles...

?>
``````

1

# C，289字节

``````a[99][99],x,X,y,Y,z,Z,i,c;main(k){for(;x=getchar(),x+1;x-10||(y=0,i++))a[y++][i]=x;for(;X<i;X++)for(x=0;a[x][X]-10;x++)for(Y=X+1;Y<i;Y++)for(y=0;a[y][Y]-10;y++)if(x-y&&!(a[x][X]-79||a[y][Y]-79)){c=0;for(Z=X;Z<=Y;Z++)for(z=x<y?x:y;z<=(x>y?x:y);)a[z++][Z]-79||c++;c-2||(k=0);}putchar(k+48);}
``````