武汉科技大学ACM:1008: 零起点学算法64——回型矩阵
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——回型矩阵的更多相关文章
- 武汉科技大学ACM :1008: 零起点学算法58——开灯问题
Problem Description 计算中心有8个机房,每个机房有n台电脑.每台电脑都有一个编号,比如8号机房编号就为H1到Hn,我们有时又称为H1为1号机器,H2为2号机器,.... 有一天我们 ...
- WUOJ-ACM :1003: 零起点学算法78——牛牛
武汉科技大学ACM :1003: 零起点学算法78--牛牛Problem Description牛牛是一种纸牌游戏,总共5张牌,规则如下: 如果找不到3张牌的点数之和是10的倍数,则为没牛: 如果其中 ...
- 1163: 零起点学算法70——Yes,I can!
1163: 零起点学算法70--Yes,I can! Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1164: 零起点学算法71——C语言合法标识符(存在问题)
1164: 零起点学算法71——C语言合法标识符 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 10 ...
- 1147: 零起点学算法54——Fibonacc
1147: 零起点学算法54--Fibonacc Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 20 ...
- 1145: 零起点学算法52——数组中删数II
1145: 零起点学算法52--数组中删数II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 293 ...
- 1137: 零起点学算法44——多组测试数据输出II
1137: 零起点学算法44--多组测试数据输出II Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: ...
- 1136: 零起点学算法43——多组测试数据输出I
1136: 零起点学算法43--多组测试数据输出I Time Limit: 1 Sec Memory Limit: 128 MB 64bit IO Format: %lldSubmitted: ...
- 1135: 零起点学算法42——多组测试数据(求和)IV
1135: 零起点学算法42--多组测试数据(求和)IV Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted ...
随机推荐
- JS之路——浏览器window对象
window对象的方法 window.alert(msg) window.close() window.print() var a = window.setIntval(function,毫秒) // ...
- cypress的EZ-USB对于USB的介绍
Host is MasterThis is a fundamental USB concept. There is exactly onemaster in a USB system: the hos ...
- Solr4.8.0源码分析(12)之Lucene的索引文件(5)
Solr4.8.0源码分析(12)之Lucene的索引文件(5) 1. 存储域数据文件(.fdt和.fdx) Solr4.8.0里面使用的fdt和fdx的格式是lucene4.1的.为了提升压缩比,S ...
- 001Spark文件分析测试
使用spark-1.4.1-bin-hadoop2.6进行处理,测试文件大小为3G, 测试结果: 1:统计一个文件中某个字符的个数 scala> sc.textFile("/home/ ...
- poj 2488A Knight's Journey
#include<cstdio> #include<cstring> #define MAXN 26 using namespace std; ,,-,,-,,-,}; ,-, ...
- UOJ 218 火车管理
http://uoj.ac/problem/218 思路:建立一个可持久化线段树,代表这个位置的火车是哪辆,然后再弄一个线段树维护答案. 如果询问,直接询问线段树. 如果区间压入,直接在主席树上面压入 ...
- sql union代替or
---原始SQL SQL> SELECT deptno FROM emp WHERE empno = 7788 OR job = 'SALESMAN' ORDER BY 1; DEPTNO -- ...
- UVA11388 GCD LCM(数论)
题目链接. 题意: 给定两个数,一个G,一个L,找出两个数a,b(a<=b),使得这两个数的最大公约数为G,最小公倍数为L,且(a最小). 分析: 当a,b存在时,a一定为G. 自己证了一下,数 ...
- House Robber——LeetCode
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
- Extjs 4.2.0 MVC 架构
内容: 1. 文件结构 2. 创建项目 3. 定义控制器 4. 定义视图 5. 控制Grid 6. 创建Model和Store 7. 通过Model保存数据 8. 保存到服务器端 大型客户端程序通常都 ...