标签:
组员 石鹤李海超
一、题目
#include<iostream.h>
int main()
{
int floor[19]={0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},j,k,x=1;
int sum,temp=0;
for(k=1;k<=18;k++)
{
for(j=1;j<k;j++)
{
if(floor[j]==0)
{
continue;
}
else
{
temp+=(k-j)*floor[j];
}
}
for(j=k+1;j<=18;j++)
{
if(floor[j]==0)
{
continue;
}
else
{
temp+=(j-k)*floor[j];
}
}
if(k==1)
sum=temp;
if(temp<=sum)
{
sum=temp;
x=k;
}
temp=0;
}
cout<<x;
}
四、结果截图

五、实验心得
没有相处好的优化方法,只能使用原始的全部遍历的方法求出
标签:
原文地址:http://www.cnblogs.com/shishi1993-/p/4440253.html