hdu4772 水模拟
题意:
给你两个矩阵,问你两个矩阵的最大相同元素个数(位置也要求相同),矩阵可以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 水模拟的更多相关文章
- CodeForces.158A Next Round (水模拟)
CodeForces.158A Next Round (水模拟) 题意分析 校赛水题的英文版,坑点就是要求为正数. 代码总览 #include <iostream> #include &l ...
- CodeForces.71A Way Too Long Words (水模拟)
CodeForces71A. Way Too Long Words (水模拟) 题意分析 题怎么说你怎么做 没有坑点 代码总览 #include <iostream> #include & ...
- 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 ...
- 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 ...
- 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 ...
- BZOJ 1088 水模拟
BZOJ水一道~ 枚举前两个位置是否放雷,模拟向下推.能够则ans++ #include "stdio.h" #include "string.h" int a ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- STL中常用容器及操作 学习笔记1
@[TOC](下面介绍STL中常见的容器及操作)## 不定长数组 vector> vetcor:其实就是一个数组或者说是容器 其操作不同于之前直接定义的数组 > 而且可以直接赋值也可以直接 ...
- Python 元类编程实现一个简单的 ORM
概述 什么是ORM? ORM全称"Object Relational Mapping",即对象-关系映射,就是把关系数据库的一行映射为一个对象,也就是一个类对应一个表,这样,写代码 ...
- 测试平台系列(5) 引入Ant Design Pro
引入Ant Design Pro 回顾 还是继续回顾下之前的作业, 返回的中文变成了ascii字符,不要紧,我们光荣地百度一哈. 随便点进去看看,都可以找到正确答案: 可以看到,我们需要修改confi ...
- 关于PHP的表单数组提交显示
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title></title> 5 <meta chars ...
- ASP.NET Core扩展库之实体映射
在分层设计模式中,各层之间的数据通常通过数据传输对象(DTO)来进行数据的传递,而大多数情况下,各层数据的定义结构大同小异,如何在这些定义结构中相互转换,之前我们通过使用AutoMapper库,但Au ...
- postman接口自动化测试之添加Tests检查点
一.概念 Postman的Tests本质上是JavaScript代码,通过我们编写测试代码,每一个Tests返回True,或是False,以判断接口返回的正确性. 其实,每一个Tests实际上就是一个 ...
- P1012 拼数(JAVA语言)
//早起刷题傻一天 题目描述 设有nn个正整数(n≤20)(n≤20),将它们联接成一排,组成一个最大的多位整数. 例如:n=3n=3时,33个整数1313,312312,343343联接成的最大整数 ...
- x64dbg 条件断点相关文档
输入 字符格式 条件断点 Input When using x64dbg you can often use various things as input. Commands Commands ha ...
- 深入理解Java并发框架AQS系列(三):独占锁(Exclusive Lock)
一.前言 优秀的源码就在那里 经过了前面两章的铺垫,终于要切入正题了,本章也是整个AQS的核心之一 从本章开始,我们要精读AQS源码,在欣赏它的同时也要学会质疑它.当然本文不会带着大家逐行过源码(会有 ...
- Android Studio 之 ImageView 学习笔记
•参考资料 [1]:菜鸟教程 [2]:bilibili视频教程 •src和blackground的区别 background通常指的都是背景,而src指的是内容 当使用 src 填入图片时,是按照图片 ...