赞
踩
import java.util.*; public class Main{ static int N = 1005; static int[][] f = new int[N][N]; public static void main(String[] args){ Scanner in = new Scanner(System.in); int n = in.nextInt();//n行 int m = in.nextInt();//m列 int q = in.nextInt();//查询矩阵个数 for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ int x = in.nextInt(); f[i][j]=f[i-1][j]+f[i][j-1]-f[i-1][j-1]+x; } } for(int i=1;i<=q;i++){ int res=0; int x1 = in.nextInt();//矩阵开始坐标 int y1 = in.nextInt(); int x2 = in.nextInt();//结束坐标 int y2 = in.nextInt(); //System.out.println(f[x2][y2]+" "+f[x1-1][y2]+" "+f[x2][y1-1]); res+=(f[x2][y2]-f[x1-1][y2]-f[x2][y1-1]+f[x1-1][y1-1]);//要加上重复减去的 System.out.println(res); } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。