|
|
288 楼,
--第八题:
--先证明:总颜色数不限,每个点不超过两种颜色,则6个点必定出现单色三角形
--假设6点为ABCDEF, 从A出发有5条线,A只能用两种颜色,则其中必定有三条线为同色。
--假设为AB,AC,AD,红颜色。则点B,C,D不能再用红色,因为和A的连线已经用掉了。这样B,C,D分别只能用一种颜色,三角形BCD必定为同色。
--世界上任意6个人当中,至少有3个人相互认识,或者相互不认识
--SQL 暴力证明
with t as (select level n from dual connect by level <= 6 ),
triangle as (
select t1.n A,t2.n B,t3.n C
from t t1,t t2,t t3
where t1.n < t2.n
and t2.n < t3.n ),
triangle_3e as ( select x.A,x.B,x.C,y.A S,y.B E
from triangle x,triangle y
where x.A = y.A and x.B = y.B and x.C = y.C
union all
select x.A,x.B,x.C,y.B S,y.C E
from triangle x,triangle y
where x.A = y.A and x.B = y.B and x.C = y.C
union all
select x.A,x.B,x.C,y.A S,y.C E
from triangle x,triangle y
where x.A = y.A and x.B = y.B and x.C = y.C
),
edge as (
select s,e,row_number() over(order by s,e) rno
from (
select distinct A S,B E
from (
select A,B from triangle
union all
select B,C from triangle
union all
select A,C from triangle
)
)
),
color as (select '0' c from dual
union all
select '1' from dual),
solution (lvl,clist) as (select 1,c from color
union all
select lvl+1,
s.clist||color.c
from solution s,color
where lvl < (select count(*) from edge)
),
r as (
select clist
from solution
where lvl = (select count(*) from edge)
),
solution_v as (
select clist,s,e,substr(clist,rno,1) v
from r,
edge
)
select clist --没有单色三角形的着色方案不存在(即所有的着色方案都存在单色三角形)
from r
where clist not in (
select --r.clist,t.A,t.B,t.C, listagg(sv.v) within group (order by r.clist,t.A,t.B,t.C,sv.s,sv.e) vlist
distinct r.clist
from r,triangle_3e t,solution_v sv
where sv.clist = r.clist
and sv.s = t.s
and sv.e = t.e
group by r.clist,t.A,t.B,t.C
having listagg(sv.v) within group (order by r.clist,t.A,t.B,t.C,sv.s,sv.e) in ('000','111')
--order by r.clist,t.A,t.B,t.C
) |
|