题意:

      给你两个矩阵,问你两个矩阵的最大相同元素个数(位置也要求相同),矩阵可以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. HDR(高动态范围)

    一: 简介 一般来说,当存储在帧缓冲(Framebuffer)中时,亮度和颜色的值是默认被限制在0.0到1.0之间的. 但是如果我们遇上了一个特定的区域,其中有多个亮光源使这些数值总和超过了1.0,又 ...

  2. 从零搭建一个IdentityServer——单页应用身份验证

    上一篇文章我们介绍了Asp.net core中身份验证的相关内容,并通过下图描述了身份验证及授权的流程: 注:改流程图进行过修改,第三方用户名密码登陆后并不是直接获得code/id_token/acc ...

  3. CVE-2019-12409-Apache Solr JMX服务远程代码执行

    漏洞分析 https://www.freebuf.com/vuls/218730.html 漏洞介绍 该漏洞源于默认配置文件solr.in.sh中的ENABLE_REMOTE_JMX_OPTS配置选项 ...

  4. java关于字符串是否存

    1, if('true'.equalsIgnoreCase(response.result as String)); 2,   if (scvrsp.toLowerCase().contains(&q ...

  5. RabbitMQ简介、安装、基本特性API--Java测试

    新的阅读体验地址:http://www.zhouhong.icu/post/141 本篇文章所有的代码:https://github.com/Tom-shushu/Distributed-system ...

  6. 如何优雅的移植JavaScript组件到Blazor

    Blazor作为一个新兴的交互式 Web UI 的框架,有其自身的优缺点,如果现有的 JavaScript 组件能移植到 Blazor,无疑让 Blazor 如虎添翼,本文就介绍一下自己在开发 Bul ...

  7. 01-Spring概述(总览)

    Spring概述 前言 Spring 发展至现在,俨然成为一个生态,但要理解其余的 Spring Boot.Spring Cloud 等框架,需要先对 Spring 的整个体系有一定的理解,因为其余的 ...

  8. 循环单链表定义初始化及创建(C语言)

    #include <stdio.h> #include <stdlib.h> /** * 含头节点循环单链表定义,初始化 及创建 */ #define OK 1; #defin ...

  9. Python3中变量作用域nonlocal的总结

    最近,在工作中踩到了一个关于Python3中nonlocal语句指定的变量作用域的坑.今天趁周六休息总结记录一下. 众所周知,Python中最常见的作用域定义如下:   但是,为了更加方便地在闭包函数 ...

  10. go语言几个最快最好运用最广的web框架比较

    比较一下常用的golang web框架 令人敬畏的Web框架 如果你为自己设计一个小应用程序,你可能不需要一个Web框架,但如果你正在进行生产,那么你肯定需要一个,一个好的应用程序. 虽然您认为自己拥 ...