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 ...
随机推荐
- arti车是大幅度发地方大幅度发
转: arti车是大幅度发地方大幅度发 arti车是大幅度发地方大幅度发 转: arti车是大幅度发地方大幅度发
- 腾讯一面问我SQL语句中where条件为什么写上1=1
目录 where后面加"1=1″还是不加 不用where 1=1 在多条件查询的困惑 使用where 1=1 的好处 使用where 1=1 的坏处 where后面加"1=1″还是 ...
- Zeebe服务学习1-简单部署与实现demo
1.Zeebe是什么? Camunda公司研发的工作流引擎Zeebe,目标是对微服务的编排.具体详细介绍可以参考官网:https://zeebe.io/what-is-zeebe/ 2.背景 随着微服 ...
- mongoDB服务器连接不上Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException:
一大早打开node项目就报错,终端报 UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFU ...
- 使用HTML、jquery、DOM创建文本
<html> <head> <meta charset="utf-8"> <meta charset="utf-8"& ...
- spring 最权威的知识点
1.Spring是什么? Spring是一个轻量级的IoC和AOP容器框架.是为Java应用程序提供基础性服务的一套框架,目的是用于简化企业应用程序的开发,它使得开发者只需要关心业务需求.常见的配置方 ...
- WinForm的Socket实现简单的聊天室 IM
1:什么是Socket 所谓套接字(Socket),就是对网络中不同主机上的应用进程之间进行双向通信的端点的抽象. 一个套接字就是网络上进程通信的一端,提供了应用层进程利用网络协议交换数据的机制. 从 ...
- 让 Java 中 if else 更优雅的几个小技巧
对于一个高级 crud 工程师而言,if else 是写代码时使用频率最高的关键词之一,然而有时过多的 if else 会让我们优雅的 crud 代码显得不那么优雅,并且感到脑壳疼
- Android Studio 如何运行单个activity
•写在前面 调试界面运行单个 Activity 可节省编译整个项目的时间提高效率: 本着提高效率的角度,特地上网百度相关知识: •解决方法 首先,在 AndroidManifest.xml 文件中,找 ...
- Android Studio 之 制作 Nine-Patch 图片(.9图片)
•引言 9.png 可以保证图片在合适的位置进行局部拉伸,避免了图片全局缩放造成的图片变形问题. 但是由于Android Studio对于.9图片的检查更加严格,所以不符合AS要求的.9图片会带来很多 ...