Y
来源:互联网 发布:阿里云备案拍照怎么拍 编辑:程序博客网 时间:2024/06/08 07:51
Y - 奇数阶魔方
HDU - 1998#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <string.h>
const int max=110;
int main(){
int t;
scanf("%d",&t);
int n;
int a[21][21];
while(t--){
scanf("%d",&n);
memset(a,0,sizeof(a));
a[0][n/2]=1;
int i=0,j=n/2;
int x,y;
for(int k=2;k<=n*n;k++){
x=i-1;y=j+1;
if(x<0)x=n-1;
if(y>n-1)y=0;
//开始将数组全部置为0的好处,判断某位置是否有数只需if(位置)就行。
if(a[x][y]){
a[++i][j]=k;
}
else {
a[x][y]=k;
i=x;j=y;
}
}
for(int j=0;j<n;j++){
for(int z=0;z<n;z++)
//输出格式一共占4格,%4d就可以,输出默认为右对齐,且不用加空格。
//左对齐:%-4d,-表示为左对齐。
printf("%4d",a[j][z]);
printf("\n");
}
}
return 0;
}
- y
- y
- Y
- Y
- Y
- Y
- y
- Y
- Y
- y
- Y
- Y
- Y
- Y
- Y
- Y
- Y
- Y-Combinator
- 面向对象特征——继承及重写
- Hibernate的编程细节——事务回滚
- Bailian3718 位操作练习【位运算】
- Hibernate核心类和接口
- wxPython_下载和安装
- Y
- CentOs7 安装 nodejs
- 15418 HW1 学习心得
- Ubuntu完全教程,让你成为Ubuntu高手!
- 《七点三刻》有价值的新闻早餐 2017年11月18日星期六,第009期
- Linux 登陆shell,交互shell以及环境变量读取顺序
- p1项目,预测波士顿房价
- Java ConcurrentModificationException异常原因和解决方法
- NOIP2017 【游记】