Openjudge-NOI题库-蛇形填充数组

题目描述 Description

用数字1,2,3,4,...,n*n这n2个数蛇形填充规模为n*n的方阵。

蛇形填充方法为:

对于每一条左下-右上的斜线,从左上到右下依次编号1,2,...,2n-1;按编号从小到大的顺序,将数字从小到大填入各条斜线,其中编号为奇数的从左下向右上填写,编号为偶数的从右上到左下填写。

比如n=4时,方阵填充为如下形式:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHcAAABcCAIAAADbML0oAAAEqElEQVR4nO2dTbKsIAyF3y562INehCMH7oKJ5UKsYi3shTUxfwNt5ScgxBBfvc6pO+ryBvykA+aI/ceJ+uvP0x34CQllDgllDgllDgllDgllDuUpG/V5D9pSN2jX6f36vF+f92uij+6cc2be43/GlaABr8PH32LaYgCUrR62LuqZmrJdp/PKWT1Sg7brRH7x7DrNAVSrBwLKhww15aR/Znmrxg4Xw4+E0ShbYaWcyOqZ4ku9yajWIYZRMrRr9ChlUi5bb4+k3CnpI9KFe5KyUTSz0xFvHpZ5+HwHmpl7gLZ6xDB5iDI14m0ujWIaTduEc3adUN1+gjI9YueAwdthMjQK9/1gp9wHMRSZdGrdWsAC4aWcgiAdbv5w7pCXzYIdH/m7kuCPBLdZkpuoD+V62e3ZeYvcvt66EDZdOKlj8Egoc0goc0goc0goc0goc0goc0goc0goc0goc0gocyhDuZfT7NUZOlQbiN3rNHgurFFleztXLTqKOFaPzcZ4Xh0NUKuHc0AYRXf99pEx6RWsyYX0zQJV1ioyBtYgAGN1oxyXJTsUx+sqn9AFFsr4JjJHYSiTZ4xexeXQXTYLeX25inJrxvhOgJ0s928TtE+90NoOkYqUvxNg7ewXqsNzVkF0zOMNoMz8CsYy/TKjciwDoGvWy30XBkSU/5m8DB1WSbnXgxl0LOJEbLV6jHKSBlPKcYowM9m9QxTK6oHw9iG8YGwZI0oRcIKFx/J5E0V9exYY5MTLAN8jJ/zyJfer8b1lcAA4h0kdg0NCmUNCmUNCmUNCmUNCmUNCmUNCmUNCmUNCmUNCmUNFyj023HZ9XH4LDof12kUVkkoe9n6EwlTxzfyaxoGWsl+WC1zn24G3UtGiwb2lQamssRZ44WEHTYxwubzsSClzYzMFpLTWTu0PgDt4kw9DY6VSV47UuJqMKZGj/DVVaSlT7M9vbQI+ClPjL1DeTdXc6WQoH1vGOo9l0qSxRayhjHO4s5St3ncmN1H27G5iyn5ePvIdM2XYzK9QhrLnxDdQPq6Mc/SUnQu3/ZPHv6CMRuxylP3tmw2UAzuq15LLlbt1I2KB8h3ELkMZ8KtqfT8vMv1Y9qPTe6BZyjcRu5reNs5+Z+R+lO+fNiSYctwW6jvUg7L/7imyjNHJZo4ix90GcmDDe7QuPeytDXUjY4goJJQ5JJQ5JJQ5JJQ5JJQ5JJQ5JJQ5JJQ5JJQ5lKdcesv1edOJqajZdSr9o1nwReesu5q8vq3ZCat0V8HiQf59cvm3XHumWeOWk70fSoNVlb1yMmiNKFGV3dU7JdYadxV4y6ivsocNEbTrEnyKcXcuzvlOITBT+aQoZJccqXLwZspJRMw+tf+L8vU4+yHKd34+YOsWTHnr7ZGUoWN+hXLcPmZzeZ7yrM6tztBLeX+TMu719jBlq4d4UWHW6zXGebBQDpQdy5/kIZPo7G6vMVC/efA8ZUwT+dkvNhXjB5faKYef4zZSc1M2KrgNCX6cpl55d9UfzpV5ueIt16eV2YbDsyCB6R76LaHq+CV3NQnelOKq3FUPGhBc6hgcEsocEsocEsocEsocEsocEsocEsocEsoc+gtKAbcxPrAk1wAAAABJRU5ErkJggg==" alt="" />

 输入输出格式 Input/output
输入格式:
输入一个不大于10的正整数n,表示方阵的行数.
输出格式:
输出该方阵,相邻两个元素之间用单个空格间隔。
 输入输出样例 Sample input/output
样例测试点#1
输入样例:

4

输出样例:
1 2 6 7
3 5 8 13
4 9 12 14
10 11 15 16
 

思路:我先以一个5*5的例子开头吧,如下图所示是一个已经填充好的蛇形数组:

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAV4AAAE2CAIAAACm7m16AAAgAElEQVR4n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Mor6SEs1cFF/N7Rc6UlHEj/O96uBUujCiTH041Ek4qiJ71NiBtkZdcyXriV/hQtaDcRhQ5SwmRoqUaMXVRj9EJ5Iflp4Lu9pAF3VgN0x65I8gypUqFvfiC/Fb4i6HbGKtFGDngYYpAbRZN6DtmHLYKjiDOGtb33YUgw6Ic+hLmM92c55sxpUFTqKlPr/GlDByPrG2BHrD3kOaRnrzHbOa9WgrdBRquj/VIIKRtY3WztikKiqQtR3qkFhoUOeSGpRwcj6ZmtHDGJV1Yn6QjXoLHRIlE0nKhhZ32ztiMGjqmpRX6UG/cNmyAtgZH3D2HY45DlHVZWjvkcNygsdYqV9Q4r7YhqYbXkBvlXVj/oSNegvdIiV9g0xsb7Z8gLYadc3qMFEoUMMoYKR9c2WF0B9PY+YV4OJKocYQg0xsb5hDij08KuCyeeFaojcQa4jvCYe+I5UwaRiqKpKMEjhTaVGNYyuZC7sJvY+zsR0SfszUMObShVqANa3LY4Ku481oPZnwMRuSfsDdIsWNRiK93GLmKjnDXUUQJ+4Gsix4oUb7SgAj9G4GjjxefO8Pq4Gj8cTiavB4/FE4mrweDyRuBo8Hk8krgaPxxOJq8Hj8UTiavB4PJH8H2Q66IE4DpOzAAAAAElFTkSuQmCC" alt="" width="257" height="227" />

图中的kk根红线代表有kk次循环,kk=2*n-1

每次按照红线的箭头来存放数字,对于循环的次数i来说,如果i是单数,则数字存放是由左下往右上,如果i是双数,则数字存放是由右上往左下。

这里要分两种情况来讨论:

  <1>:当循环是下图中的①部分时,每次循环的次数都会递增1,第一次循环是从1开始,第二次循环是2、3,第三次循环是4、5、6

那么对于每次循环的开始和止点,通过观察都可以得出一个普遍结论,当i是奇数时,循环次数为i次,a[i-j][j]就可以递增;当i是偶数,循环次数还是i次,a[j][i-j],也是递增

  <2>:当循环是下图中的②部分时,每次循环的次数也是递增1,第一次循环是16、17、18、19,第二次循环是20、21、22,以此类推,每次需要循环的次数都是递减的,这时候循环的次数和循环的起止点都不和i<=n时一样了,这时候就需要重新寻找规律,我在这里定义了一个k来计算循环到达的层数,例如16、17、18、19这是第一层,这样就可以很方便地用k和n来控制循环次数,我得出了一个普遍公式:j从0开始一直到n-k循环,如果i是奇数,则每次递增a[i-j-k][j+k],如果i是偶数,则每次递增a[j+k][i-j-k]即可。

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAXAAAAE6CAIAAACAuJ5iAAAgAElEQVR4nO2dO6s0R5KGjzUIBgYZMkYgGGdgjYVhnTFq7YEFWbKXhfHKXZAhcz3Z7S0CGWvPHyhHCPYHDKw70Ej/QIaQIQSCWKP6Upe8RGRGVEWcfh8+6zt9+ryVFfl0VmZW9RsBAIASb2cHAAC8HyAUAIAaEAoAQA0IBQCgBoQCAFADQgEAqAGhABCO62UYp7NDJHlhoUzj2xKnJ+jJ9TK4jzlnfIvSsOsScBx0zTT6TfuiQpnG7Rm5Xoa34XI9K1CNR+k7rSNayGRuxlVn9Zc6pT6XQXfcGtZp0lcUyvUyJM/H3jI+WNW+x4BE2UZ9aMWXrKdxE+nZxl4b+Ib3T5YXFMo05srb41DykelW8s7i3SiM7x5d1U/yaUyFvQf1k3PPNL4Ng+uYLyeU2fCZs7H74DqXlfo8C+V6GfKtdu+oXto1O6HpuYWJ6C5CXPJ4ouiTW0l5qfw1jsu96JPnKN1j9CW+Z72vl2HOBqE4onYy5p+7NIpjoVS4NbrLVl2Qm1pzwUMnEIonbp0yX9qOT1ZYocQYoLhe5VvoxHWN0qsJpfpZWTXOeUQViuMmfbDqsO7YpINQ3FCfx3c80x9UKI4vIm8sN8w4zLmTHYTiBgjlaMpz4Oez2S3tTyqJsROE4gYI5VicrcLvmMbUR7+jRk5eikEoboBQDuR6GVzbJMXm7gEHaTIbuv0WwksJpX4uIBQl8tuRfeNnSSo7UQyh+KG6yuN4y0QgoUS1CZGbCkhN7mTxVBOvJRTmxjZXZ+hOFKG43tBRx8kqN4QSg0qv9NxpPWd7ENwmFKGZz/vQ++GTP87/Cq95MaFwbg50Wkz+K71mk2kM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+cgqicN1R8ry2HCIUzMNlRu5WX+/pSWuFvCP7046UqLcuOyl8L2eda1XrTFtDDoibfya4AGqMmf62hHuZfFP9a4Q0V32uLvVA6tq7ZonuSTDkwam9BnNCqZ99tbE0ooaiyP3K3NqE49USIakOUqBDKDc82oTj1RIhqQ5SoEAqRe5tQnHoiRLUhStRXF0rr3cNHE6WeCFFtiBL1pYUSxSYUp54IUW2IEvV1hRLIJhSnnghRbYgS9UWFEkglM1HqiRDVhihRX1Eo4WxCceqJENWGKFFfTigRbUJx6okQ1YYoUV9LKEFtQnHqiRDVhihRX0goSZu8AQC0Uey2HoWSW9A5u9kBeJ8odl53Qom1PAwAWOJLKLAJAKFxJBTYBIDoeBEKVALAO8CFUGATAN4H5wsFNgHg3XCyUGATAN4TpwkFU7AAvD/OEQpsAsC75AShwCYAvFeOFgpsAsA75lChQCUAvG+OEwpsAsC75yChwCYAvAJHCAU2AeBFsBUKpmABeCn+H1y38FHuhQYLAAAAAElFTkSuQmCC" alt="" width="279" height="239" />

代码如下:

 #include <stdio.h>
int main()
{
int n,i,j;
int kk;
int o=;//用来改变数组的变量
int k=;
int a[][];
scanf("%d",&n);
kk=*n-;//控制总循环次数
for(i=;i<=kk;i++)
{
/*===========================*///①部分
if(i%==&&i<n)//递增
{
for(j=;j<=i;j++)
{
a[i-j][j]=o;
o++;
}
}
else if(i%==&&i<n)//递减
{
for(j=;j<=i;j++)
{
a[j][i-j]=o;
o++;
}
}
/*===========================*///②部分
else if(i%==&&i>=n)//递增
{
for(j=;j<n-k;j++)
{
a[i-j-k][j+k]=o;
o++;
}
k++;
}
else if(i%==&&i>=n)//递减
{
for(j=;j<n-k;j++)
{
a[j+k][i-j-k]=o;
o++;
}
k++;
}
}
for(i=;i<n;i++)//输出结果
{
for(j=;j<n;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
return ;
}
上一篇:Win7系统(台式机)设置系统的窗口背景色(豆沙绿色)


下一篇:Windows7WithSP1/TeamFoundationServer2012update4/SQLServer2012