题意:

      给你两个矩阵,问你两个矩阵的最大相同元素个数(位置也要求相同),矩阵可以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. 剑指 Offer 56 - II. 数组中数字出现的次数 II + 位运算

    剑指 Offer 56 - II. 数组中数字出现的次数 II Offer_56_2 题目详情 解题思路 java代码 package com.walegarrett.offer; /** * @Au ...

  2. PyCharm之python package和directory的区别

    python作为一门解释性的脚本语言.python中模块就是指一个py文件,如果我们将所有相关的代码都放在一个py文件中,则该py文件既是程序又是是模块,但是程序和模块的设计目的是不同的,程序的目的是 ...

  3. 如何在 C# 中使用 ArrayPool 和 MemoryPool

    对资源的可复用是提升应用程序性能的一个非常重要的手段,比如本篇要分享的 ArrayPool 和 MemoryPool,它们就有效的减少了内存使用和对GC的压力,从而提升应用程序性能. 什么是 Arra ...

  4. 分形、分形几何、数据可视化、Python绘图

    本系列采用turtle.matplotlib.numpy这三个Python工具,以分形与计算机图像处理的经典算法为实例,通过程序和图像,来帮助读者一步步掌握Python绘图和数据可视化的方法和技巧,并 ...

  5. CF533F Encoding 题解

    题目链接CF533F Encoding 提示1:   \(\mathcal O(26^2*n)\) 的算法可通过.常用的几种字符串匹配算法kmp,AC自动机,哈希都可以解决该问题 (后两者可以优化到 ...

  6. Java并发编程之锁机制

    锁分类 悲观锁与乐观锁 悲观锁认为对于同一个数据的并发操作,一定是会发生修改的,哪怕没有修改,也会认为修改.因此对于同一个数据的并发操作,悲观锁采取加锁的形式.悲观的认为,不加锁的并发操作一定会出问题 ...

  7. Python图像处理库——PIL

    PIL全称Python Image Library,是python官方的图像处理库,包含各种图像处理模块.Pillow是PIL的一个派生分支,包含与PIL相同的功能,并且更灵活.python3.0之后 ...

  8. 系统编程-信号-总体概述和signal基本使用

    信号章节 -- 信号章节总体概要 信号基本概念 信号是异步事件,发送信号的线程可以继续向下执行而不阻塞. 信号无优先级. 1到31号信号是非实时信号,发送的信号可能会丢失,不支持信号排队. 31号信号 ...

  9. 使用Amazon Pinpoint对用户行为追踪

    1.前言 最近在做一个项目,我们的后台大数据团队需要了解用户在使用app的时候,都进行了哪些操作,在哪个页面都干了些什么,以及app日活和月活等等,各种数据.总之就是监控用户行为,说好听一点就是发送反 ...

  10. Macbook 安装kali linux 双系统 2020.3 超详细

    博主折腾了一星期这东西,到现在都还有些坑没解决(最后面会讲).不过最起码系统装上了,可以用了,看到这桌面惊艳了,再点下左上角表示人间值得. 其实我是装了windos 10.macos 和kali三系统 ...