WA #4,谁能帮忙hack一下qwq

P2455 [SDOI2006] 线性方程组

dblark @ 2019-07-01 19:55:29

由于我是 Pascal 党,贴代码不知道有没有人看的懂……

{P2455}
var
  a: array [1..50, 1..51] of real;
  n, i, j, k, max: longint;
  t: real;
procedure swap(var x, y: real);
var
  t: real;
begin
  t := x;
  x := y;
  y := t;
end;
begin
  read(n);
  for i := 1 to n do
    for j := 1 to n + 1 do
      read(a[i, j]);
  for i := 1 to n do
  begin
    max := i;
    for j := i + 1 to n do
      if abs(a[j, i]) > abs(a[max, i]) then
        max := j;
    for j := 1 to n + 1 do
      swap(a[i, j], a[max, j]);
    if a[i, i] <> 0 then
      for j := 1 to n do
        if i <> j then
        begin
          t := a[j, i] / a[i, i];
          for k := i + 1 to n + 1 do
            a[j, k] := a[j, k] - a[i, k] * t;
        end;
  end;
  for i := 1 to n do
    if (a[i, i] = 0) and (a[i, n + 1] <> 0) then
    begin
      writeln(-1);
      halt;
    end;
  for i := 1 to n do
    if (a[i, i] = 0) and (a[i, n + 1] = 0) then
    begin
      writeln(0);
      halt;
    end;
  for i := 1 to n do
    if a[i, n + 1] = 0 then
      writeln('x', i, '=0') 
    else
      writeln('x', i, '=', a[i, n + 1] / a[i, i] : 0 : 2);
end.

by dblark @ 2019-07-01 19:55:59

用的是高斯-约旦消元法


by little_gift @ 2019-07-01 20:00:42

dblark!


by hehezhou @ 2019-07-01 20:27:17

@dblark

2
0 2 3
0 0 0

by dblark @ 2019-07-02 17:01:14

@hehezhou -1


by hehezhou @ 2019-07-02 17:33:44

@dblark 显然是0


|