HDU4772--Zhuge Liang's Password(160)
来源:互联网 发布:java中md5加密怎么写 编辑:程序博客网 时间:2024/04/30 13:03
【题目】点击打开链接
【题解】这道题就是考察一个矩阵旋转的算法。输入并不难,就是对两个矩阵进行0度,90度,180度,270度旋转看是否有数字相同。
设i,j是行和列,则对于
0度:a[i][j]=b[i][j];
90度:
- 列号变为行号
- (n - 行号 + 1)变成列号
- 规律: a[i][j] = b[j][n - i + 1]
180度:
- (n - 行号 + 1)变为行号
- (n - 列号 + 1)变为列号
- 规律:a[i][j] = b[n - i + 1][n - j + 1]
- 行号变为列号
- (n - 列号 + 1)变为行号
- 规律:a[i][j] = b[n - j + 1][i]
#pragma warning(disable:4786)#include<iostream>#include<algorithm>#include<cmath>#include<stdio.h>#include<time.h>#include<stdlib.h>#include<queue>#include<set>#include<vector>#include<string>#include<ctime>#include<string.h>using namespace std;#define pi acos(-1.0)//#define LL __int64typedef long long LL;#define INF 0x7fffffffffffffff#define bug puts("hear!")#define inf 0x7fffffff#define eps 1e-10#define FRE freopen("in.txt","r",stdin)#define E exp(1.0)#define mod 1000000007#define len 35int switchMatrix(int (*a)[len], int (*b)[len], int n);int s[len][len];int main(){ int i, j, n, angle; int a[len][len], b[len][len]; while(scanf("%d", &n) != EOF&&n!=0) { for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { scanf("%d", *(a + i) + j); } } for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { scanf("%d", *(b + i) + j); } } angle = switchMatrix(a, b, n); printf("%d\n", angle); } return 0;}int switchMatrix(int (*a)[len], int (*b)[len], int n){ int angle, i, j,f; angle=0;f=0; for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { if(a[i][j]==b[i][j]) angle++; } } for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { if(a[i][j]==b[j][n-i+1]) f++; } } if(f>angle)angle=f; f=0; for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { if(a[i][j] == b[n - i + 1][n - j + 1]) f++; } } if(f>angle)angle=f; f=0; for(i = 1; i <= n; i ++) { for(j = 1; j <= n; j ++) { if(a[i][j] == b[n - j + 1][i]) f++; } } if(f>angle)angle=f; return angle;}
- HDU4772--Zhuge Liang's Password(160)
- HDU4772-Zhuge Liang's Password
- hdu4772 Zhuge Liang's Password
- hdu4772 Zhuge Liang's Password
- HDU4772 2013 Asia Hangzhou Regional Contest C Zhuge Liang's Password
- hdu4772 水题 Zhuge Liang's Password (2013 Asia Hangzhou Regional Contest problem C)
- D - Zhuge Liang's Password
- Zhuge Liang's Password--选拔赛
- HDU 4772 Zhuge Liang's Password (简单模拟题)
- 2013杭州站C - Zhuge Liang's Password(模拟)
- HDU 4772 Zhuge Liang's Password(暴力)
- 7_11_C题 Zhuge Liang's Password(模拟)
- UVALive 6456Zhuge Liang's Password (water~~)
- hdu 4772Zhuge Liang's Password(水题)
- hdu 4772 Zhuge Liang's Password
- Hdu 4772 Zhuge Liang's Password
- HDU 4772 Zhuge Liang's Password
- HDU 4772 --Zhuge Liang's Password
- 数据结构-双向链表
- Android-开启蓝牙
- ExtJs中decode与encode
- Lisp语言发明者 人工智能奠基人 John McCarthy
- OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows,
- HDU4772--Zhuge Liang's Password(160)
- android 测试分享图片+文字到微博
- UNIX / Linux: 10 Netstat Command Examples
- Ant的实现原理
- android游戏物理引擎开发——重力引擎(一)
- 用PhysicsEditor快速创建自定义Box2D刚体
- 我们了解SEO,一定要有一个正确的认识
- 回文 反序 素数
- Ping Tutorial: 15 Effective Ping Command Examples