hdu 2153 仙人球的残影
2014-03-24 12:04
204 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2153
#include<iostream>
const int MAX=10;
int a[MAX][MAX];
using namespace std;
int main()
{
int n,x,y,tot=0;
while(scanf("%d",&n),n>=1&&n<=10)
{
memset(a,0,sizeof(a));
tot=a[x=0][y=0]=1;
while(tot<(n-1)*4)//只转一圈,4*n-4
{
while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot;
while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot;
while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot;
while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot;
}
for(x=0;x<n;x++)n
{
for(y=0;y<n;y++)
if(a[x][y]==0)
printf(" ");
else
printf("=",a[x][y]);
printf("\n");
}
}
return 0;
}
#include<iostream>
const int MAX=10;
int a[MAX][MAX];
using namespace std;
int main()
{
int n,x,y,tot=0;
while(scanf("%d",&n),n>=1&&n<=10)
{
memset(a,0,sizeof(a));
tot=a[x=0][y=0]=1;
while(tot<(n-1)*4)//只转一圈,4*n-4
{
while(y+1<n&&!a[x][y+1]) a[x][++y]=++tot;
while(x+1<n&&!a[x+1][y]) a[++x][y]=++tot;
while(y-1>=0&&!a[x][y-1]) a[x][--y]=++tot;
while(x-1>=0&&!a[x-1][y]) a[--x][y]=++tot;
}
for(x=0;x<n;x++)n
{
for(y=0;y<n;y++)
if(a[x][y]==0)
printf(" ");
else
printf("=",a[x][y]);
printf("\n");
}
}
return 0;
}
相关文章推荐
- HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)
- HDU 2153 仙人球的残影
- hdu 2153 仙人球的残影
- HDU 2153 仙人球的残影
- HDOJ(HDU) 2153 仙人球的残影(谜一样的题、、、)
- hdu 2153 仙人球的残影
- HDU 2153 仙人球的残影(类蛇形填数)
- hdu 2153 仙人球的残影新解法(可以利用蛇阵来解决哦!)
- HDU 2153 仙人球的残影
- HDU 2153 仙人球的残影.
- HDU 2153 仙人球的残影
- (解题报告)HDU2153———仙人球的残影
- hdu-2153-仙人球的残影
- HDU 2153 仙人球的残影 (字符串处理,类似蛇形矩阵)
- hdu 2153 仙人球的残影
- HDU 2153 --仙人球的残影
- hdu 2153 仙人球的残影
- 【紫书】蛇形填数P40+nyoj33蛇形填数(原题)+ hdu2153仙人球的残影(变形蛇形填数) +nyoj852蛇形填数(二)
- HDOJ 2153 仙人球的残影(水题)
- hd 2153 仙人球的残影