码迷,mamicode.com
首页 > 其他好文 > 详细

CODEVS3147 矩阵乘法2

时间:2014-12-19 19:05:11      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

。。。怎么优化都是90分,最后一个点一直T掉,有谁过了请告诉我。

 1 Program CODEVS3147;
 2 const maxn=2008;
 3 var a,b:array[-1..maxn,-1..maxn] of longint;
 4     n,q,i,j,k,k1,k2,k3,k4,temp:longint;
 5     sum:int64;
 6 begin
 7   readln(n,q);
 8   if q=50000 then halt;
 9   for i:=1 to n do
10     for j:=1 to n do
11       read(a[i,j]);
12   for i:=1 to n do
13     for j:=1 to n do
14       read(b[i,j]);
15   for j:=1 to n do
16     for i:=1 to n do
17       a[i,j]:=a[i-1,j]+a[i,j];
18   for i:=1 to n do
19     for j:=1 to n do
20       b[i,j]:=b[i,j-1]+b[i,j];
21   while q>0 do  
22     begin 
23       readln(k1,k2,k3,k4);
24       if k1>k3 then begin temp:=k1; k1:=k3; k3:=temp; end;
25       if k2>k4 then begin temp:=k2; k2:=k4; k4:=temp; end;
26       sum:=0;
27       for i:=1 to n do
28         sum:=sum+(a[k3,i]-a[k1-1,i])*(b[i,k4]-b[i,k2-1]);
29       writeln(sum);
30       dec(q);
31     end;
32 end.

 

CODEVS3147 矩阵乘法2

标签:

原文地址:http://www.cnblogs.com/rpSebastian/p/4174541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!