题意:

      给你两个矩阵,问你两个矩阵的最大相同元素个数(位置也要求相同),矩阵可以90旋转多次。

思路:

      水题,直接模拟就行了,方法很多,可以直接写坐标关系,或者一层一层处理,就是一层一层往里拿出来,比较就行了,两个都写了。

直接交换

#include<stdio.h>

int A[32][32] ,B[32][32] ,C[32][32];

void swap(int n)

{

   for(int i = 1 ;i <= n ;i ++)

   for(int j = 1 ;j <= n ;j ++)

   C[i][j] = A[j][n-i+1];

   for(int i = 1 ;i <= n ;i ++)

   for(int j = 1 ;j <= n ;j ++)

   A[i][j] = C[i][j];

}

int main ()

{

   int n ,i ,j ,ans;

   while(~scanf("%d" ,&n) && n)

   {

      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]);

      int ans = 0;

      for(int c = 1 ;c <= 4 ;c ++)

      {

         int sum = 0;

         for(i = 1 ;i <= n ;i ++)

         for(j = 1 ;j <= n ;j ++)

         if(A[i][j] == B[i][j]) sum ++;

         if(ans < sum) ans = sum;

         swap(n);

      }

      printf("%d\n" ,ans);

   }

   return 0;

}

一层一层比较

#include<stdio.h>

int get_len(int c ,int n ,int A[32][32] ,int C[])

{

   int tmp = 0 ,i;

   for(i = c ;i <= n - c + 1 ;i ++)

   C[++tmp] = A[c][i];

   for(i = c + 1 ;i <= n - c + 1 ;i ++)

   C[++tmp] = A[i][n - c + 1];

   for(i = n - c + 1 - 1 ;i >= c ;i --)

   C[++tmp] = A[n - c + 1][i];

   for(i = n - c + 1 - 1 ;i >= c + 1 ;i --)

   C[++tmp] = A[i][c];

   return tmp;

}

int main ()

{

   int A[32][32] ,B[32][32] ,C[1000] ,D[1000];

   int i ,j ,n;

   int sum[5];

   while(~scanf("%d" ,&n) && n)

   {

      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]);

      sum[1] = sum[2] = sum[3] = sum[4] = 0;

      for(int c = 1 ;c <= (n + 1) / 2 ;c ++)

      {

          int tmp1 = get_len(c ,n ,A ,C);

          int tmp2 = get_len(c ,n ,B ,D);

          for(i = 1 ;i <= 4 ;i ++)

          {

              for(j = 1 ;j <= tmp1 ;j ++)

              {

                 int now = j + (n - c + 1 - c) * (i - 1);

                 if(now > tmp1) now -= tmp1;

                 if(C[now] == D[j]) sum[i] ++;

              }           

         }

      }

      int ans = 0;

      for(i = 1 ;i <= 4 ;i ++)

      if(ans < sum[i]) ans = sum[i];

      printf("%d\n" ,ans);

   }

   return 0;

}

          

          

         

          

          

          

          

    

          

            

         

   

hdu4772 水模拟的更多相关文章

  1. CodeForces.158A Next Round (水模拟)

    CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...

  2. CodeForces.71A Way Too Long Words (水模拟)

    CodeForces71A. Way Too Long Words (水模拟) 题意分析 题怎么说你怎么做 没有坑点 代码总览 #include <iostream> #include & ...

  3. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  4. Codeforces Round #301 (Div. 2)A B C D 水 模拟 bfs 概率dp

    A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

    A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input ...

  6. BZOJ 1088 水模拟

    BZOJ水一道~ 枚举前两个位置是否放雷,模拟向下推.能够则ans++ #include "stdio.h" #include "string.h" int a ...

  7. Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心

    A. The New Year: Meeting Friends time limit per test 1 second memory limit per test 256 megabytes in ...

  8. Codeforces Round #374 (Div. 2) A B C D 水 模拟 dp+dfs 优先队列

    A. One-dimensional Japanese Crossword time limit per test 1 second memory limit per test 256 megabyt ...

  9. Codeforces Round #277 (Div. 2) A B C 水 模拟 贪心

    A. Calculating Function time limit per test 1 second memory limit per test 256 megabytes input stand ...

随机推荐

  1. 184. 部门工资最高的员工 + join + in

    184. 部门工资最高的员工 LeetCode_MySql_184 题目描述 题解分析 1.首先需要使用group by找出工资最高的值 2. 然后考虑到最高工资的可能有多位,所以使用in语句找到所有 ...

  2. 40. 组合总和 II + 递归 + 回溯 + 记录路径

    40. 组合总和 II LeetCode_40 题目描述 题解分析 此题和 39. 组合总和 + 递归 + 回溯 + 存储路径很像,只不过题目修改了一下. 题解的关键是首先将候选数组进行排序,然后记录 ...

  3. 10个顶级Python实用库,推荐你试试!

    为什么我喜欢Python?对于初学者来说,这是一种简单易学的编程语言,另一个原因:大量开箱即用的第三方库,正是23万个由用户提供的软件包使得Python真正强大和流行. 在本文中,我挑选了15个最有用 ...

  4. 强化学习导论 课后习题参考 - Chapter 1,2

    Reinforcement Learning: An Introduction (second edition) - Chapter 1,2 Chapter 1 1.1 Self-Play Suppo ...

  5. 在CentOS上安装Nginx配置HTTPS并设置系统服务和开机启动(最全教程)

    友情提示:全部配完大约需要20分钟,本教程配合 xshell 和 xftp 使用更佳. 系统配置:CentOS 7.5 本教程 摘繁华 版权所有. 操作按键 常用按键: 复制操作:Shift+Ins ...

  6. 用 Go + WebSocket 快速实现一个 chat 服务

    前言 在 go-zero 开源之后,非常多的用户询问是否可以支持以及什么时候支持 websocket,终于在 v1.1.6 里面我们从框架层面让 websocket 的支持落地了,下面我们就以 cha ...

  7. java例题_25 判断是否为回文数!

    1 /*25 [程序 25 求回文数] 2 题目:一个 5 位数,判断它是不是回文数.即 12321 是回文数,个位与万位相同,十位与千位相同. 3 */ 4 5 /*分析 6 * 先用%和/将5个数 ...

  8. Android Studio 如何在TextView中设置图标并按需调整图标大小

    •任务 相信大家对这张图片都不陌生,没错,就是 QQ动态 向我们展示的界面. 如何实现呢? •添加文字并放入图标 新建一个 Activity,取名为 QQ,Android Studio 自动为我们生成 ...

  9. OpenCV 之 平面单应性

    上篇 OpenCV 之 图象几何变换 介绍了等距.相似和仿射变换,本篇侧重投影变换的平面单应性.OpenCV相关函数.应用实例等. 1  投影变换 1.1  平面单应性 投影变换 (Projectiv ...

  10. 最短路径(Dijskra算法)

    声明:图片及内容基于:https://www.bilibili.com/video/BV16C4y1H7Zc?from=articleDetail 最短路径 Dijkstra算法 原理 数据结构 核心 ...