ac1042.pas

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

PAS
44
字号
program tju1042;
const
  maxn=10000;
type
  list=array[0..maxn]of longint;
var
  a,b:list;
  t,u,n,i,x:longint;
  ok:boolean;
procedure qsort(var a:list;s,t:word);
  var
    p,i,j,tmp:longint;
  begin
    if s>=t then exit;
    p:=s+random(t-s+1);
    tmp:=a[p];a[p]:=a[s];
    i:=s;j:=t;
    repeat
      while (i<j) and (a[j]>=tmp) do dec(j);
      if i=j then break;a[i]:=a[j];inc(i);
      while (i<j) and (a[i]<=tmp) do inc(i);
      if i=j then break;a[j]:=a[i];dec(j);
    until i=j;
    a[i]:=tmp;
    qsort(a,s,i-1);
    qsort(a,i+1,t);
  end;
begin
  read(t);
  for u:=1 to t do begin
    read(n);
    for i:=1 to n do begin read(x);a[i]:=a[i-1]+x;end;
    for i:=1 to n do begin read(x);b[i]:=b[i-1]+x;end;
    if b[n]<>0 then begin writeln('NO');continue;end;
    qsort(a,1,n);qsort(b,1,n);
    x:=a[1]-b[1];ok:=true;
    for i:=2 to n do
      if a[i]-b[i]<>x then begin
        ok:=false;break;
      end;
    if ok then writeln('YES') else writeln('NO');
  end;
end.

⌨️ 快捷键说明

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