欧拉图由一个二维平面上的简单封闭形状组成,每个平面都描述一个集合或类别。如何或是否这些形状重叠显示集合之间的关系。
我是个被宠坏的孩子,他认为欧拉图很难画出来。对于任何欧拉图,我想知道两个形状的圆周相交的最小点数。下面是一个例子:

上面绘制的欧拉图表示一种关系,其中:
foo和bar是不相交的。baz都是foo,但反之亦然。qux是baz;有些qux是foo,但不是baz;还有一些qux是bar。baz都是qux;不是所有的非baz foo都是qux;也不是所有的bar都是qux。在这个特殊的例子中,你不能比一个巨大的六个十字路口做得更好,但这就是生活。
输入:多个整数的序列,如下所示。
输入格式不是固定的。例如,Python或JS对象也一样好--在这种情况下,星号(*)行就不那么必要了。
请注意,输入是保证不会产生‘飞地’(就像这张照片里一样,即‘半人马’)。
输出:在欧拉图中,两种形状的周长的最小交叉次数。
为了您的利益,请输入括号内的备注:
1 (Consider the set designated by 1.)
0 (It's not a proper subset of anything.)
0 (It's equivalent to no other set.)
1 (It's a proper superset of:)
3 (the set designated by 3.)
1 (It; the set designated by 1; contains part but not all of:)
4 (the set designated by 4.)
2 (Consider the set designated by 2.)
0 (It's not a proper subset of anything.)
0 (It's equivalent to no other set.)
0 (It's not a proper superset of anything.)
1 (It contains part but not all of:)
4 (the set designated by 4.)
3 (Consider the set designated by 3.)
1 (It's a proper subset of:)
1 (the set designated by 1.)
0 (It; the set designated by 3; is equivalent to no other set.)
0 (It's not a proper superset of anything.)
1 (It contains part but not all of:)
4 (the set designated by 4.)
4 (Consider the set designated by 4.)
0 (It's not a proper subset of anything.)
0 (It's equivalent to no other set.)
0 (It's not a proper superset of anything.)
3 (It contains part but not all of:)
1 (the set designated by 1,)
2 (the set designated by 2 and)
3 (the set designated by 3.)输出:6
这个例子与“前提”部分中的一个完全匹配(设置1为foo,2 bar,3 baz,4 qux)。
假设我们希望输入类似于JS对象。一种可能是:
{
1:[[],[],[3],[4]],
2:[[],[],[],[4]],
3:[[1],[],[],[4]],
4:[[],[],[],[1,2,3]]
}输入:1 0 0 1 2 1 3 2 1 1 0 0 1 3 3 0 0 0 2 1 2
输出:4
请看这里。
假设我们希望输入类似于JS对象。一种可能是:
{
1:[[],[],[2],[3]],
2:[[1],[],[],[3]],
3:[[],[],[],[1,2]]
}发布于 2021-04-08 16:17:54
function n=E(s)
i=2;k=1;n=0;while i<numel(s)
k=mod(k,4)+1;n=n+s(i)*((k==1)-(k==3)/2);i=i+s(i)+1+(k<2);end未打高尔夫球的:
function n=E(s) % function def, input 2 and output n
i=2; % sequence index
k=1; % 1=sub,2=equivalent,3=super,4=part
n=0; % initialized output
while i<numel(s) % Loop through sequence
k=mod(k,4)+1; % if k==4, then a new set has started, so back to 1.
n=n+s(i)*((k==1)-(k==3)/2); % s(i) represents n,m,p,q
% If k==1, then s(i)=q, so add s(i) to n.
% If k==3, s(i)=m, so subtract s(i)/2 from n.
i=i+s(i)+1+(k<2); % Advance index by (n,m,p,q) and 1 if k==1 (aka k<2) to skip set number definition.
end % end解释:
这可能是一种天真的方法,但据我所见,只有当你有一个集合作为另一个集合的一部分时,才能有一个更完美的交集。
对于超级/子集,将没有周边交叉口,因为它们将是同心圆。
对于完全匹配的集合,只会有一个表示两组的形状,因此它们之间没有周界交叉。
因此,唯一可以重叠的时间是对部分进行重叠。这样做很简单:每一个交叉都包括两个点,因为根据重叠矩形的性质,将有两个,而且只有两个交点的周长。由于包含另一部分的集合必须相互引用(即,如果集合1和2重叠,集合1将在其部分输入中有2,而2将有1),则将有2*(集合的数目属于另一部分)。但是,完全相等的集合只产生一个形状,因此必须根据等效的集合数减少该形状与另一个形状之间的任何交叉。因此,所有集合中属于“部件”类别的元素数量之和等于数字交叉。
从数学上讲,
对于k集
https://codegolf.stackexchange.com/questions/203966
复制相似问题