首页 > 其他 > 详细

网易游戏编程题第二题

时间:2017-02-19 22:47:33      阅读:284      评论:0      收藏:0      [点我收藏+]

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;
}

网易游戏编程题第二题

原文:http://www.cnblogs.com/YTYMblog/p/6417629.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!