HDU4772-Zhuge Liang's Password

简介:

Zhuge Liang's Password
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 541    Accepted Submission(s): 370


Problem Description
  In the ancient three kingdom period, Zhuge Liang was the most famous and smart military leader. His enemy was Sima Yi, the military leader of Kingdom Wei. Sima Yi always looked stupid when fighting against Zhuge Liang. But it was Sima Yi who laughed to the end.
  Zhuge Liang had led his army across the mountain Qi to attack Kingdom Wei for six times, which all failed. Because of the long journey, the food supply was a big problem. Zhuge Liang invented a kind of bull-like or horse-like robot called "Wooden Bull & Floating Horse"(in abbreviation, WBFH) to carry food for the army. Every WBFH had a password lock. A WBFH would move if and only if the soldier entered the password. Zhuge Liang was always worrying about everything and always did trivial things by himself. Since Ma Su lost Jieting and was killed by him, he didn't trust anyone's IQ any more. He thought the soldiers might forget the password of WBFHs. So he made two password cards for each WBFH. If the soldier operating a WBFH forgot the password or got killed, the password still could be regained by those two password cards.
  Once, Sima Yi defeated Zhuge Liang again, and got many WBFHs in the battle field. But he didn't know the passwords. Ma Su's son betrayed Zhuge Liang and came to Sima Yi. He told Sima Yi the way to figure out the password by two cards.He said to Sima Yi:
  "A password card is a square grid consisting of N×N cells.In each cell,there is a number. Two password cards are of the same size. If you overlap them, you get two numbers in each cell. Those two numbers in a cell may be the same or not the same. You can turn a card by 0 degree, 90 degrees, 180 degrees, or 270 degrees, and then overlap it on another. But flipping is not allowed. The maximum amount of cells which contains two equal numbers after overlapping, is the password. Please note that the two cards must be totally overlapped. You can't only overlap a part of them."
  Now you should find a way to figure out the password for each WBFH as quickly as possible.
 

Input
  There are several test cases.
  In each test case:
  The first line contains a integer N, meaning that the password card is a N×N grid(0<N<=30).
  Then a N×N matrix follows ,describing a password card. Each element is an integer in a cell.
  Then another N×N matrix follows, describing another password card.
  Those integers are all no less than 0 and less than 300.
  The input ends with N = 0
 

Output
  For each test case, print the password.

 

Sample Input
2
1 2
3 4
5 6
7 8
2
10 20
30 13
90 10
13 21
0
 

Sample Output
0
2
 

Source
2013 Asia Hangzhou Regional Contest
 

//矩阵旋转
AC代码:

#include<stdio.h>
#include<string.h>
int a[40][40],b[40][40];
void Rotate(int n)
{
 int i,j,c[40][40],x=0,y=n-1;
    for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
            c[i][j]=b[x++][y];
   if(x>n-1)
   {
                x=0;y--;
   }
  }

 for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
   b[i][j]=c[i][j];
  }
}
int main()
{
 int i,j,n,m,sum,max;
 while(scanf("%d",&n),n!=0)
 {
  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));
  max=0;
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
   scanf("%d",&a[i][j]);
        for(i=0;i<n;i++)
  for(j=0;j<n;j++)
   scanf("%d",&b[i][j]);
        
  sum=0;
  for(i=0;i<n;i++)
  for(j=0;j<n;j++)
  {
   if(a[i][j]==b[i][j])
    sum++;
  }
  if(sum>max)
   max=sum;
       
  int T=3;
  while(T--)
  {
            Rotate(n);
   sum=0;
            for(i=0;i<n;i++)
   for(j=0;j<n;j++)
   {
    if(a[i][j]==b[i][j])
     sum++;
   }
   if(sum>max)
    max=sum;
  }
  printf("%d\n",max);
 }
 return 0;
}
相关文章
|
数据中心 运维 网络协议
|
人工智能 文字识别 监控
将人工智能融入多媒体 助力视频产业加速——阿里云视频AI全能力解读
结合人工智能视频理解流程和用户的需求场景,我们将视频AI的功能分成四个大部分,视频智能审核、视频内容理解、视频智能编辑、视频版权保护。其中视频审核功能包括视频鉴黄、暴恐涉政识别、广告二维码识别、无意义直播识别等,利用识别能力将网络上没营养和不健康的视频内容进行排查和处理;视频理解功能包括视频分类、标签,人物识别、语音识别,同时也包括对视频中的文字进行识别(OCR);视频编辑层面可以实现视频首图、视频摘要、视频highlight的生成,同时支持新闻拆条;关于视频版权,支持视频相似性、同源视频检索和音视频指纹等功能。
17688 0
将人工智能融入多媒体 助力视频产业加速——阿里云视频AI全能力解读
|
10月前
|
消息中间件 运维 安全
后端开发中的微服务架构实践与挑战####
在数字化转型的浪潮中,微服务架构凭借其高度的灵活性和可扩展性,成为众多企业重构后端系统的首选方案。本文将深入探讨微服务的核心概念、设计原则、关键技术选型及在实际项目实施过程中面临的挑战与解决方案,旨在为开发者提供一套实用的微服务架构落地指南。我们将从理论框架出发,逐步深入至技术细节,最终通过案例分析,揭示如何在复杂业务场景下有效应用微服务,提升系统的整体性能与稳定性。 ####
194 32
|
10月前
|
SQL 存储 Apache
Apache Doris 3.0.3 版本正式发布
亲爱的社区小伙伴们,Apache Doris 3.0.3 版本已于 2024 年 12 月 02 日正式发布。该版本进一步提升了系统的性能及稳定性,欢迎大家下载体验。
404 16
|
Oracle 关系型数据库 Linux
VMware的竞品
VMware的竞品
313 2
|
弹性计算 缓存 数据挖掘
阿里云通用算力型u1云服务器配置性能评测及价格参考
阿里云通用算力型u1云服务器是企业级云服务器规格,通用算力型u1实例规格的云服务器提供2c-32c规格和1:1/2/4/8丰富配比,因此,通用算力型u1实例既有2核2G、2核4G这种配置可选,也有2核8G、2核16G这种配置可选,通用算力型u1实例云服务器是阿里云各个活动中价格最便宜的,下面小编分享通用算力型u1实例的配置、性能评测及优惠信息,看看这个实例的阿里云服务器是否值得购买。
阿里云通用算力型u1云服务器配置性能评测及价格参考
|
前端开发 搜索推荐 UED
单页面应用(SPA)与多页面应用(MPA)的区别及优缺点
单页面应用(SPA)与多页面应用(MPA)的区别及优缺点
364 1
|
分布式计算 大数据 物联网
从历年 Gartner hype cycle 看大数据行业的发展历史和趋势
从历年 Gartner hype cycle 看大数据行业的发展历史和趋势