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 ...
随机推荐
- POJ-3268(来回最短路+dijkstra算法)
Silver Cow Party POJ-3268 这题也是最短路的模板题,只不过需要进行两次求解最短路,因为涉及到来回的最短路之和. 该题的求解关键是:求解B-A的最短路时,可以看做A是起点,这就和 ...
- C#连接Excel读取与写入数据库SQL ( 下 )
接上期 dataset简而言之可以理解为 虚拟的 数据库或是Excel文件.而dataset里的datatable 可以理解为数据库中的table活着Excel里的sheet(Excel里面不是可以新 ...
- 小白的第一次sql实战
去年发的有一篇sql注入忘记粘贴过来了,今天想起了就fuzz过来一下 有id尝试sql注入 找这种sql注入的站用sql检索就行了,但是最好挂代理用谷歌搜索,百度的话搜sql注入的很多被别人打过了,导 ...
- 【Azure Developer】Github Action部署资源(ARM模板)到Azure中国区时,遇见登录问题的解决办法
问题描述 在参考文档"使用 GitHub Actions 部署 ARM 模板"一文中,由于是在中国区Azure上操作,所以生产的部署凭证为中国区凭证.当创建工作流时,在登录到Azu ...
- 微信小程序--简约风博客小程序(基于云开发 - 全开源)
微信小程序--简约风博客小程序(基于云开发 - 全开源) 项目启动纯属突发奇想,想看看博客小程序,例如wehalo博客小程序,但是感觉自建平台还要浪费自己的服务器算力,还没有访问量,省省吧. 本着白嫖 ...
- Python - 关于类(self/cls) 以及 多进程通讯的思考
Python-多进程中关于类以及类实例的一些思考 目录 Python-多进程中关于类以及类实例的一些思考 1. 背景 2. Python 类中的函数 - staticmethod / classmet ...
- IndexError: list index out of range Python常见错误
引用超过list最大索引,此错误非常常见,注意列表的元素个数 ----------------------------------------------
- crx 文件安装 如何安装 Chrome插件
Chrome 67 版本(大概2018.06.06的更新包)开始,插件已经无法离线安装啦,也就是自己无法使用crx文件安装插件, 而只能从chrome.google.com/webst ...
- python3使用kivy生成安卓程序
技术背景 虽然现在苹果占据了很大一部分的市场,但是从销量数据来看,安卓还是占据了人口的高地.这里我们介绍一个用python的kivy+buildozer来进行安卓APP开发的简单教程,从整个过程中来看 ...
- BUAA_OO_第四单元
一.UML解析器设计 先看下题目:第四单元实现一个基于JDK 8带有效性检查的UML(Unified Modeling Language)类图,顺序图,状态图分析器 MyUmlInteractio ...