2018 蓝桥杯省赛 B 组模拟赛(五) A 结果填空:矩阵求和

题目链接: https://nanti.jisuanke.com/t/25084
有许多种解法,只要能暴力出来就行,观察题可以发现符合要求的数距离中心点都不超过n/2,所以遍历一遍地图,找出符合条件的点就行了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <vector>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 101;

int main(){
	int temp=101;
	int map1[105][105];
	int n=1,sum=0;
	for(int i=0;i<temp;i++){
		for(int j=0;j<temp;j++){
			map1[i][j]=n++;
			if(abs(temp/2-i)+abs(temp/2-j)<=temp/2){
				sum+=map1[i][j];
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/abc1235454/article/details/88741283
今日推荐