I and OI
Past...

高斯消元.

参考:http://blog.csdn.net/dfs35123/article/details/5823013

/************************************************************** 
    Problem: 1778
    User: exponent 
    Language: Pascal 
    Result: Accepted 
    Time:696 ms 
    Memory:1212 kb 
****************************************************************/ 
  
const maxn=301; 
var   link:array[0..maxn,0..maxn] of boolean; 
      m:array[0..maxn,0..maxn] of extended; 
      x,b:array[0..maxn] of extended; 
      c:array[0..maxn] of longint; 
      n,e,px,qx,o,u,v,i,j,k:longint; 
      poss,sum,t:extended; 
  
  
  
begin
      readln(n,e,px,qx); 
      poss:=px/qx; 
      for o:=1 to e do
      begin
            readln(u,v); 
            inc(c[u]); 
            inc(c[v]); 
            link[u,v]:=true; 
            link[v,u]:=true; 
      end; 
  
      b[1]:=poss; 
      for u:=1 to n do
      begin
            m[u,u]:=1; 
            for v:=1 to n do
               if link[u,v] then m[u,v]:=-(1-poss)/c[v]; 
      end; 
  
      for k:=1 to n-1 do
         for i:=k+1 to n do
         begin
               t:=m[i,k]/m[k,k]; 
               for j:=k+1 to n do
                  m[i,j]:=m[i,j]-m[k,j]*t; 
               b[i]:=b[i]-b[k]*t; 
         end; 
  
      for i:=n downto 1 do
      begin
            sum:=0; 
            for j:=n downto i+1 do
               sum:=sum+m[i,j]*x[j]; 
            x[i]:=(b[i]-sum)/m[i,i]; 
      end; 
  
      for i:=1 to n do writeln(x[i]:0:9); 
  
end.
posted on 2011-08-20 17:26  exponent  阅读(355)  评论(0编辑  收藏  举报