题意:

      给你两个矩阵,问你两个矩阵的最大相同元素个数(位置也要求相同),矩阵可以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. Hexo的详细搭建过程——小白的血泪经历QAQ

    Hexo的详细搭建过程 环境要求: node.js git 这里提供Centos8.2下的安装过程: dnf module list nodejs dnf module install nodejs: ...

  2. 精确率precession和召回率recall

    假设有两类样本,A类和B类,我们要衡量分类器分类A的能力. 现在将所有样本输入分类器,分类器从中返回了一堆它认为属于A类的样本. 召回率:分类器认为属于A类的样本里,真正是A类的样本数,占样本集中所有 ...

  3. Elasticsearch 模块 - Shard Allocation 机制

    原文 1. 背景 shard allocation 意思是分片分配, 是一个将分片分配到节点的过程; 可能发生该操作的过程包括: 初始恢复(initial recovery) 副本分配(replica ...

  4. 【MaixPy3文档】写好 Python 代码!

    本文是给有一点 Python 基础但还想进一步深入的同学,有经验的开发者建议跳过. 前言 上文讲述了如何认识开源项目和一些编程方法的介绍,这节主要来说说 Python 代码怎么写的一些演化过程和可以如 ...

  5. 死磕Spring之IoC篇 - @Bean 等注解的实现原理

    该系列文章是本人在学习 Spring 的过程中总结下来的,里面涉及到相关源码,可能对读者不太友好,请结合我的源码注释 Spring 源码分析 GitHub 地址 进行阅读 Spring 版本:5.1. ...

  6. HTB系列之七:Bastard

    出品|MS08067实验室(www.ms08067.com) 这次挑战的是 HTB 的第7台靶机:Bastard 技能收获: PHP Unserilaize CMS Version Identify ...

  7. 第七届蓝桥杯省赛JavaB组——第十题压缩变换

    题目: 压缩变换小明最近在研究压缩算法.他知道,压缩的时候如果能够使得数值很小,就能通过熵编码得到较高的压缩比.然而,要使数值很小是一个挑战.最近,小明需要压缩一些正整数的序列,这些序列的特点是,后面 ...

  8. MySQL入门(3)——数据类型

    MySQL入门(3)--数据类型 数字类型 整数数据类型: 数据类型 取值范围 说明 单位 TINYINT 符号值:-127~127无符号值:0~255 最小的整数 1字节 BIT 符号值:-127~ ...

  9. HDU_3333 Turing Tree 【线段树 + 离散化】

    一.题目 Turing Tree 二.分析 这题主要还是在区间的处理上. 为了保证区间内的数没有重复的,那么可以对区间按右端点从小到大排序,这样对原数组处理时,尽量保证不重复的元素靠右(可以假设右端点 ...

  10. JS利用cookie记录当前位置实现刷新页面后还可以保持菜单栏的展开或闭合

    代码如下,重点是JS部分的代码(部分样式引用的是Bootstrapt中的):   <style> .sidebar-menu .special{ font-size: 16px; marg ...