AcWing 750. 数组的下方区域,曼哈顿距离稍作修改
原题链接
中等
作者:
jenbwo
,
2024-04-11 22:07:43
,
所有人可见
,
阅读 1
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
char s = 'S' , m = 'M' , L ;
cin >> L ;
double x = 0 , count = 0;
int d = 11 ,c = 0;
for (int i = 0; i < 12 ; i ++ )
{
for (int j = 0; j < 12; j ++ )
{
cin >> x ;
if(j < 6) if( abs(i - d) + abs(j - 5) < 5) count += x , c++ ; //曼哈顿距离(11,5)为中心
if(j > 5) if( abs(i - d) + abs(j - 6) < 5) count += x , c++ ; //曼哈顿距离(11,6)为中心
}
}
if(L == s) printf("%.1lf" , count);
if(L == m) printf("%.1lf" , count / c);
return 0;
}