时间限制:1 秒

内存限制:32 兆

特殊判题:否

提交:4649

解决:1530

题目描述:

首先输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。

操作类型有四种:  

1 2 表示:90度,顺时针,翻转4个数  

1 3 表示:90度,顺时针,翻转9个数  

2 2 表示:90度,逆时针,翻转4个数  

2 3 表示:90度,逆时针,翻转9个数

输入:

输入有多组数据。

每组输入一个5 * 5的数组,然后输入一行,这一行有四个数,前两个代表操作类型,后两个数x y代表需操作数据为以x y为左上角的那几个数据。

输出:

输出翻转后的数组。

样例输入:
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
1 3 1 1
样例输出:
11 6 1 4 5
12 7 2 9 10
13 8 3 14 15
16 17 18 19 20
21 22 23 24 25
来源:
2010年北京邮电大学计算机研究生机试真题

思路:

总体思路是每次旋转90度,超过就多次旋转。可能犯错的细节较多,多调试。

代码:

#include <stdio.h>

#define M 5

struct point {
int i;
int j;
}; struct point rotate(int n, int i, int j, int x, int y, int degree)
{
struct point p;
p.i = i;
p.j = j;
int tmp;
for (int k=1; k<=degree/90; k++)
{
tmp = p.i;
p.i = (x-y) + p.j;
p.j = (x-1) + (y-1) + n-1 - tmp;
}
return p;
} int main(void)
{
int i, j;
int d, n, x, y;
int a[M][M], b[M][M];
struct point p;
int degree; while (scanf("%d", &a[0][0]) != EOF)
{
for(i=0; i<M; i++)
{
for(j=0; j<M; j++)
{
if (i == 0 && j == 0)
continue;
scanf("%d", &a[i][j]);
}
}
scanf("%d%d%d%d", &d, &n, &x, &y); if (d == 1)
degree = 90;
else
degree = 270; for(i=0; i<M; i++)
{
for(j=0; j<M; j++)
{
if (i<x-1 || i>=x-1+n || j<y-1 || j>=y-1+n)
b[i][j] = a[i][j];
else
{
p = rotate(n, i, j, x, y, degree);
b[p.i][p.j] = a[i][j];
}
}
}
//printf("i=%d, j=%d\n", i, j);
for(i=0; i<M; i++)
{
for(j=0; j<M; j++)
{
if (j != 0)
printf(" ");
printf("%d", b[i][j]);
}
printf("\n");
}
} return 0;
}
/**************************************************************
Problem: 1171
User: liangrx06
Language: C
Result: Accepted
Time:0 ms
Memory:912 kb
****************************************************************/

九度OJ 1171:C翻转 (矩阵计算)的更多相关文章

  1. 【九度OJ】题目1171:C翻转 解题报告

    [九度OJ]题目1171:C翻转 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1171 题目描述: 首先输入一个5 * 5的数组,然 ...

  2. 【九度OJ】题目1026:又一版 A+B 解题报告

    [九度OJ]题目1026:又一版 A+B 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1026 题目描述: 输入两个不超过 ...

  3. 【九度OJ】题目1074:对称平方数 解题报告

    [九度OJ]题目1074:对称平方数 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1074 题目描述: 打印所有不超过n( ...

  4. 【九度OJ】题目1177:查找 解题报告

    [九度OJ]题目1177:查找 解题报告 标签(空格分隔): 九度OJ http://ac.jobdu.com/problem.php?pid=1177 题目描述: 读入一组字符串(待操作的),再读入 ...

  5. 【九度OJ】题目1208:10进制 VS 2进制 解题报告

    [九度OJ]题目1208:10进制 VS 2进制 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1208 题目描述: 对于一 ...

  6. 九度oj 题目1087:约数的个数

    题目链接:http://ac.jobdu.com/problem.php?pid=1087 题目描述: 输入n个整数,依次输出每个数的约数的个数 输入: 输入的第一行为N,即数组的个数(N<=1 ...

  7. 九度OJ 1502 最大值最小化(JAVA)

    题目1502:最大值最小化(二分答案) 九度OJ Java import java.util.Scanner; public class Main { public static int max(in ...

  8. 九度OJ,题目1089:数字反转

    题目描述: 12翻一下是21,34翻一下是43,12+34是46,46翻一下是64,现在又任意两个正整数,问他们两个数反转的和是否等于两个数的和的反转. 输入: 第一行一个正整数表示测试数据的个数n. ...

  9. 九度OJ 1500 出操队形 -- 动态规划(最长上升子序列)

    题目地址:http://ac.jobdu.com/problem.php?pid=1500 题目描述: 在读高中的时候,每天早上学校都要组织全校的师生进行跑步来锻炼身体,每当出操令吹响时,大家就开始往 ...

随机推荐

  1. 强连通分量(Tarjan)模板

    贴模板,备忘. 模板1: #include<iostream> #include<cstring> #include<cmath> #include<cstd ...

  2. 串口调试利器--Minicom配置及使用详解

    因为现在电脑基本不配备串行接口,所以,usb转串口成为硬件调试时的必然选择.目前知道的,PL2303的驱动是有的,在dev下的名称是ttyUSB*. Minicom,是Linux下应用比较广泛的串口软 ...

  3. Linux运维:CentOS6和7的区别

    Liunx笔记:CentOS6和CentOS7的区别 路飞学城运维人员 在线流程图软件 Ago linux运维群: 93324526 笔者QQ:578843228 常用安装包下载 yum instal ...

  4. 苹果iOS APP配置HTTPS,iOS ATS配置SSL,苹果ATS标准解决方案

    参考沃通:

  5. 【POI】导出xls文件报错:The maximum number of cell styles was exceeded. You can define up to 4000 styles in a .xls workbook

    使用POI导出xls文件,由于数据过多,导致导出xls报错如下: The maximum number of cell styles was exceeded. You can define up t ...

  6. LeakCanary: 让内存泄露无所遁形

    LeakCanary: 让内存泄露无所遁形 09 May 2015 本文为LeakCanary: Detect all memory leaks!的翻译.原文在: https://corner.squ ...

  7. 用PHP实现弹出消息提示框

    方法一: echo "<script>alert('提示内容')</script>"; 方法二: echo '<script language=&qu ...

  8. 在cmd窗口输入命令遇到You must run this command from a command prompt with administrator privilege怎么办?

    点开始菜单,找到Accessories(附件),找到Command Prompt窗口,点右键,选“run as administrator”(以管理员身份运行),之后再执行先前的命令就好了. 2017 ...

  9. 通过apache的mod_status 统计占资源的脚本

    apache的mod_status模块,提供了对apache运行时的一些统计信息,对apache的管理员来说很有意义. 一.加载apache的mod_status模块 各种系统下,加载apache模块 ...

  10. 一款很实用的Memcache监控工具

    装了memcahce以后想对使用情况详细了解一下,如分配的内存够不够,都存了什么,经百度后发现这款工具灰常实用!此工具来自Memcache Pecl 中 http://pecl.php.net/pac ...