Problem Description

输出n*m的回型矩阵

Input

多组测试数据
每组输入2个整数 n和m(不大于20)

Output

输出n*m的回型矩阵,要求左上角元素是1,(每个元素占2个位置,靠右)

Sample Input

4 3

Sample Output

 1  2  3
10 11 4
9 12 5
8 7 6
 #include<iostream>
#include<string.h>
#include<iomanip>
using namespace std;
int main()
{
int m,n,i,j,k,lastX,lastY;
while(cin>>m>>n)
{
int **a=new int*[m];
for(i=;i<m;i++)
{
*(a+i)=new int[n];
memset(a[i],,n*sizeof(int));
}
i=,j=,k=;
int state=;//0 为从左到右赋值,1为从上到下,2为从右到左,3为从下到上
while(k<m*n)
{//要赋值m*n次
switch(state)
{
case :
for(;j<n;++j)
{
if(a[i][j]==)
{
a[i][j]=k+;
++k;
lastX=i;
lastY=j;//记录下一次赋值开始位置
}
}
i=lastX+;
j=lastY;
state=;
break;
case :
for(;i<m;++i)
{
if(a[i][j]==)
{
a[i][j]=k+;
++k;
lastX=i;
lastY=j;
}
}
i=lastX;
j=lastY-;
state=;
break;
case :
for(;j>=;--j)
{
if(a[i][j]==)
{
a[i][j]=k+;
++k;
lastX=i;
lastY=j;
}
}
i=lastX-;
j=lastY;
state=;
break;
case :
for(;i>=;--i)
{
if(a[i][j]==)
{
a[i][j]=k+;
++k;
lastX=i;
lastY=j;
}
}
i=lastX;
j=lastY+;
state=;
break;
default:
break;
} } for(i=;i<m;i++)
{
for(j=;j<n;j++)
if(j==)
{
cout<<setw()<<a[i][j];
}
else
{
cout<<setw()<<a[i][j];
}
cout<<endl;
delete []a[i];
}
delete []a; }
return ;
}

武汉科技大学ACM:1008: 零起点学算法64——回型矩阵的更多相关文章

  1. 武汉科技大学ACM :1008: 零起点学算法58——开灯问题

    Problem Description 计算中心有8个机房,每个机房有n台电脑.每台电脑都有一个编号,比如8号机房编号就为H1到Hn,我们有时又称为H1为1号机器,H2为2号机器,.... 有一天我们 ...

  2. WUOJ-ACM :1003: 零起点学算法78——牛牛

    武汉科技大学ACM :1003: 零起点学算法78--牛牛Problem Description牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中 ...

  3. 1163: 零起点学算法70——Yes,I can!

    1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: ...

  4. 1164: 零起点学算法71——C语言合法标识符(存在问题)

    1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 10 ...

  5. 1147: 零起点学算法54——Fibonacc

    1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 20 ...

  6. 1145: 零起点学算法52——数组中删数II

    1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: 293 ...

  7. 1137: 零起点学算法44——多组测试数据输出II

    1137: 零起点学算法44--多组测试数据输出II Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted: ...

  8. 1136: 零起点学算法43——多组测试数据输出I

    1136: 零起点学算法43--多组测试数据输出I Time Limit: 1 Sec  Memory Limit: 128 MB   64bit IO Format: %lldSubmitted: ...

  9. 1135: 零起点学算法42——多组测试数据(求和)IV

    1135: 零起点学算法42--多组测试数据(求和)IV Time Limit: 1 Sec  Memory Limit: 64 MB   64bit IO Format: %lldSubmitted ...

随机推荐

  1. PHP之路——验证码实现

    验证码生成并保存到session <?php //开始session session_start(); //画布大小 $image = imagecreate(100, 40); $color ...

  2. Xamarin Studio –Project not built in active configuration

    当我们加载项目以后如果出现以下项目提示 处理方式如下: 解决方案右键->options 配置->configuration mappings->勾选构建的ios项目 项目右键-> ...

  3. new Random().nextInt

    public static void main(String[] args) { System.out.println(new Random().nextInt(0)); } Exception in ...

  4. 【HDOJ】1717 小数化分数2

    简单字符串处理. #include <cstdio> #include <cstring> #include <cmath> #include <ctype. ...

  5. COJ 1011 WZJ的数据结构(十一)树上k大

    题解:主席树&DFS序. PS:为什么我一开始Wa了N发 是因为有一个左区间我写成[L,M+1]了.......................... #include<iostream ...

  6. 【转】设置TextView文字居中

    原文网址:http://blog.csdn.net/lanpy88/article/details/6616924 有2种方法可以设置TextView文字居中: 一:在xml文件设置:android: ...

  7. HDOJ的题目分类

    模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 10 ...

  8. 嵌入式环境搭建之NFS

    嵌入式环境搭建之NFS Author:tiger-johnTime:2013-08-04mail:jibo.tiger@gmail.comBlog:http://blog.csdn.net/tiger ...

  9. 点击按钮弹出div,留用

    <input type="button" onclick="document.getElementById('div').style.display=(docume ...

  10. RSA 非对称加密 数字签名 数字证书

    什么是RSA加密算法 RSA加密算法是一种非对称加密算法,算法的数学基础是极大数分解难题. RSA加密算法的强度也就是极大数分解的难度,目前700多位(二进制)的数字已经可以破解,1024位认为是比较 ...