首页 > 代码库 > 网易游戏编程题第二题

网易游戏编程题第二题

int GetSum(vector<int> a,int N)
{
int sum=0;
if (N>a.size())
{
for (auto &i:a)
{
sum+=i;
}
}
else
{
for (int i = 0; i < N; i++)
{
sum+=a[i];
}
}
return sum;
}
int GetMaxMatrix(vector<vector<int>> matrix,int M ,int N)
{
vector<vector<int>> s(M,vector<int>(M,0));
vector<int> sum;
for (int j = 0; j < M; j++)
{
for (int i = 0; i < M; i++)
{
s[j][i]=matrix[i][j];
}
sum.push_back(GetSum(s[j],N));
}
for (int i = 0; i < M; i++)
{
for (int j = 0; j < M; j++)
{
s[i][j]=matrix[i][j];
}
sum.push_back(GetSum(s[i],N));
}
int delta=0;
while (delta)
{
vector<int> temp;
for (int i = delta,j=0; i <M&&j<M; i++,j++)
{
temp.push_back(matrix[i][j]);
}
sum.push_back(GetSum(temp,N));
delta++;
}
delta=0;
while (delta)
{
vector<int> temp;
for (int j = delta,i=0; j < M&&i<M; j++,i++)
{
temp.push_back(matrix[i][j]);
}
sum.push_back(GetSum(temp,N));
delta++;
}
delta=0;
while (delta)
{
vector<int> temp;
for (int i = delta,j=M; i <M&&j>=0; i++,j--)
{
temp.push_back(matrix[i][j]);
}
sum.push_back(GetSum(temp,N));
}
delta=M-1;
while (delta)
{
vector<int> temp;
for (int j = delta,i=0; j >=0&&i<M; j--,i++)
{
temp.push_back(matrix[i][j]);
}
sum.push_back(GetSum(temp,N));
delta--;
}
int MAX=sum.front();
for (auto& i:sum)
{
if (MAX<i)
{
MAX=i;
}
}
return MAX;
}

网易游戏编程题第二题