http://acm.hdu.edu.cn/showproblem.php?pid=2687
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
#include<stdio.h>
![](http://www.cppblog.com/Images/OutliningIndicators/None.gif)
int main()
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedBlock.gif)
![](http://www.cppblog.com/Images/dot.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
int n,i,k,j,a[11][11],b[11][11];
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif)
while(scanf("%d",&n)!=EOF)
![](http://www.cppblog.com/Images/dot.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
scanf("%d",&a[i][j]);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
scanf("%d",&k);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++) //首先求解每循环四次的总和*(k/4)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
b[i][j]=(a[i][j]+a[j][n+1-i]+a[n+1-i][n+1-j]+a[n+1-j][i])*(k/4);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(k%4==0)//再求解k%4的结果
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
b[i][j]+=a[i][j];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
else if(k%4==1)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
b[i][j]+=a[i][j]+a[n+1-j][i];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
else if(k%4==2)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
b[i][j]+=a[i][j]+a[n+1-j][i]+a[n+1-i][n+1-j];
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
else
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
b[i][j]+=a[i][j]+a[n+1-j][i]+a[n+1-i][n+1-j]+a[j][n+1-i];
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif)
for(i=1;i<=n;i++)
![](http://www.cppblog.com/Images/dot.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://www.cppblog.com/Images/OutliningIndicators/ContractedSubBlock.gif)
for(j=1;j<=n;j++)
![](http://www.cppblog.com/Images/dot.gif)
{
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
printf("%d",b[i][j]);
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
if(j<n)
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
printf(" ");}
![](http://www.cppblog.com/Images/OutliningIndicators/InBlock.gif)
printf("\n");
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://www.cppblog.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
}
这题只要分清对应的转动位置就能求解!还要注意转动顺序!!!
posted on 2009-04-27 20:41
zhoubaozhong 阅读(287)
评论(0) 编辑 收藏 引用