6 solutions

  • -1
    @ 2025-11-20 21:44:00

    解题报告

    撰写人: 陈天翊

    题意分析

    请你编程求出二维数组中某点的相邻数之和。相邻数是指与该点邻接的 8 8 个元素,若该点在边角位置,则邻接元素相应减少。

    难度等级

    ★★☆☆☆

    解题思路

    78

    解题反思

    91

    参考程序

    #include <bits/stdc++.h>
    using namespace std;
    int h,l,c,r,a[1000][1000];
    int main(){
        cin>>h>>l>>c>>r;
        for(int i=0;i<h;i++){
            for(int j=0;j<l;j++){
                cin>>a[i][j];
            }
        }
        cout<<a[c+1][r]+a[c-1][r]+a[c][r-1]+a[c][r+1]+a[c+1][r+1]+a[c-1][r-1]+a[c+1][r-1]+a[c-1][r+1];
        return 0;
    }
    
    • -1
      @ 2025-11-18 16:58:47

      解题报告

      撰写人: 许苡键

      难度等级

      ★★☆☆☆

      参考程序

      #include<bits/stdc++.h>
      using namespace std;
      long long a[15][15],h,l,c,r,sum,dx[8]={-1,-1,-1,0,1,1,1,0};
      long long dy[8]={-1,0,1,1,1,0,-1,-1};
      bool check(int x,int y){
      	return x>=0&&x<h&&y>=0&&y<l;
      }
      int main(){
      	cin>>h>>l>>c>>r;
      	for(int i=0;i<h;i++)
      		for(int j=0;j<l;j++)
      			cin>>a[i][j];
      	for(int i=0;i<8;i++){
      		int nx=c+dx[i],ny=r+dy[i];
      		if(check(nx,ny))sum+=a[nx][ny];
      	}
      	cout<<sum;
      }
      
      • -2
        @ 2025-11-20 17:28:24

        解题报告

        撰写人: 钟世博

        题意分析

        请你编程求出二维数组中某点的相邻数之和。相邻数是指与该点邻接的 8 8 个元素,若该点在边角位置,则邻接元素相应减少。 下图以 4 4 行 5 5 列二维数组 � a 为例: � [ 2 ] [ 3 ] a[2][3] 元素的值为 7 7,其邻接元素为 8,9,10,5,8,6,8,0 和为 54 54 。再比如: � [ 1 ] [ 0 ] a[1][0] 元素的值为 6 6,则其邻接元素为 1,2,7,3,4和为 17 17。

        1 2 3 4 5 6 7 8 9 10 3 4 5 7 8 2 5 6 8 0

        参考程序

        #include <bits/stdc++.h>
        using namespace std;
        int h,l,c,r,a[1000][1000];
        int main(){
            cin>>h>>l>>c>>r;
            for(int i=0;i<h;i++){
                for(int j=0;j<l;j++){
                    cin>>a[i][j];
                }
            }
            cout<<a[c+1][r]+a[c-1][r]+a[c][r-1]+a[c][r+1]+a[c+1][r+1]+a[c-1][r-1]+a[c+1][r-1]+a[c-1][r+1];
            return 0;
        }
        
        • -2
          @ 2025-11-20 17:27:15
          
          
          #include<bits/stdc++.h>
          using namespace std;
          int n,m,x,y,a[105][105],s;
          int main()
          {
              cin>>n>>m>>x>>y;
              for(int i=0;i<=n;i++)
                  for(int j=0;j<=m;j++)
                      a[i][j]=0;
              for(int i=1;i<=n;i++)
                  for(int j=1;j<=m;j++)
                      cin>>a[i][j];
              x++,y++;
              s+=a[x-1][y-1]+a[x-1][y]+a[x-1][y+1];
              s+=a[x][y-1]+a[x][y+1];
              s+=a[x+1][y-1]+a[x+1][y]+a[x+1][y+1];
              cout<<s;
              return 0;
          }
          
          
          • -2
            @ 2025-11-20 17:07:24

            #include<bits/stdc++.h> using namespace std; long long a[15][15],h,l,c,r,sum,dx[8]={-1,-1,-1,0,1,1,1,0}; long long dy[8]={-1,0,1,1,1,0,-1,-1}; bool check(int x,int y){ return x>=0&&x<h&&y>=0&&y<l; } int main(){ cin>>h>>l>>c>>r; for(int i=0;i<h;i++) for(int j=0;j<l;j++) cin>>a[i][j]; for(int i=0;i<8;i++){ int nx=c+dx[i],ny=r+dy[i]; if(check(nx,ny))sum+=a[nx][ny]; } cout<<sum; }

            • -2
              @ 2025-11-20 17:05:08

              #include<bits/stdc++.h> using namespace std; long long a[15][15],h,l,c,r,sum,dx[8]={-1,-1,-1,0,1,1,1,0}; long long dy[8]={-1,0,1,1,1,0,-1,-1}; bool check(int x,int y){ return x>=0&&x<h&&y>=0&&y<l; } int main(){ cin>>h>>l>>c>>r; for(int i=0;i<h;i++) for(int j=0;j<l;j++) cin>>a[i][j]; for(int i=0;i<8;i++){ int nx=c+dx[i],ny=r+dy[i]; if(check(nx,ny))sum+=a[nx][ny]; } cout<<sum; }

              • 1

              Information

              ID
              292
              Time
              1000ms
              Memory
              64MiB
              Difficulty
              5
              Tags
              # Submissions
              71
              Accepted
              27
              Uploaded By