ac1119.pas

来自「某牛人写的acm.tongji.edu.cn上大部分ac的代码,仅供学习研究,请」· PAS 代码 · 共 31 行

PAS
31
字号
program tju1119;
var
  n,i:word;
begin
  repeat
    read(n);
    if (n=2) or (n=3) or (n=5) then
      writeln('Yes')
    else begin
      writeln('No');
      if odd(n) then write('2 1 1 1') else write('2 3 3 3');
      for i:=5 to n do
        write(' 3');
      writeln;
    end;
  until seekeof;
end.
{
The hard thing of this prob is to prove Fan(5)>=0 always holds.
Proof:
  Denote the five numbers by a,b,c,d,e, sorted by increasing order.
  Let A=(a-b)(a-c)(a-d)(a-e), and the similar for B,C,D,E.
  Obviously A,C,E>=0, B,D<=0.
  Compare |A| and |B|:
    Because |a-b|=|b-a|,|a-c|>=|b-c|,|a-d|>=|b-d|,|a-e|>=|b-e|
    Therefore |A|>=|B|.
    So A+B>=0.
  Similarly we can obtain that D+E>=0.
  Also because C>=0, therefore A+B+C+D+E>=0, i.e. Fan(5)>=0 always holds.
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?