UVa 340 Master-Mind Hints:优化查找&复制数组

340 - Master-Mind Hints

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=276

MasterMind is a game for two players. One of them, Designer, selects a secret code. The other, Breaker, tries to break it. A code is no more than a row of colored dots. At the beginning of a game, the players agree upon the length N that a code must have and upon the colors that may occur in a code.

In order to break the code, Breaker makes a number of guesses, each guess itself being a code. After each guess Designer gives a hint, stating to what extent the guess matches his secret code.

In this problem you will be given a secret code and a guess , and are to determine the hint. A hint consists of a pair of numbers determined as follows.

A match is a pair (i,j), and , such that . Match (i,j) is called strong when i =j, and is called weak otherwise. Two matches (i,j) and (p,q) are called independent when i = p if and only if j = q. A set of matches is called independent when all of its members are pairwise independent.

Designer chooses an independent set M of matches for which the total number of matches and the number of strong matches are both maximal. The hint then consists of the number of strong followed by the number of weak matches in M. Note that these numbers are uniquely determined by the secret code and the guess. If the hint turns out to be (n,0), then the guess is identical to the secret code.

Input

The input will consist of data for a number of games. The input for each game begins with an integer specifying N (the length of the code). Following these will be the secret code, represented as N integers, which we will limit to the range 1 to 9. There will then follow an arbitrary number of guesses, each also represented as N integers, each in the range 1 to 9. Following the last guess in each game will be N zeroes; these zeroes are not to be considered as a guess.

Following the data for the first game will appear data for the second game (if any) beginning with a new value for N. The last game in the input will be followed by a single zero (when a value for N would normally be specified). The maximum value for N will be 1000.

Output

The output for each game should list the hints that would be generated for each guess, in order, one hint per line. Each hint should be represented as a pair of integers enclosed in parentheses and separated by a comma. The entire list of hints for each game should be prefixed by a heading indicating the game number; games are numbered sequentially starting with 1. Look at the samples below for the exact format.

Sample Input

4
1 3 5 5
1 1 2 3
4 3 3 5
6 5 5 1
6 1 3 5
1 3 5 5
0 0 0 0
10
1 2 2 2 4 5 6 6 6 9
1 2 3 4 5 6 7 8 9 1
1 1 2 2 3 3 4 4 5 5
1 2 1 3 1 5 1 6 1 9
1 2 2 5 5 5 6 6 6 7
0 0 0 0 0 0 0 0 0 0
0

Sample Output

Game 1:
    (1,1)
    (2,0)
    (1,2)
    (1,2)
    (4,0)
Game 2:
    (2,4)
    (3,2)
    (5,0)
    (7,0)

学英语:

1. Match (i,j) is called strong when i =j, and is called weak otherwise.

当i=j时,匹配(i,j)被叫做强匹配,反之叫做弱匹配。

2. Two matches (i,j) and (p,q) are called independent when i = p if and only if j = q. A set of matches is called independent when all of its members are pairwise independent.

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索number
, and
, code
, of
, The
matches
uva340、uva340灯管、master mind、deepmind master、master mind japan,以便于您获取更多的相关知识。

时间: 2024-08-03 16:38:51

UVa 340 Master-Mind Hints:优化查找&复制数组的相关文章

iOS开发入门:性能优化–查找和解决僵尸对象

内存泄漏是当一个对象或变量在使用完成后没有释放掉,那么如果我们走了另外一个极端情况会什么样呢?这就导致过渡释放(over  release)问题,从而使对象"僵尸化",对象称为僵尸(zombies)对象.一个对象已经被释放过了,或者调用者没有这个对象的所有权而释放它, 都会造成过渡释放,产生僵尸对象. 僵尸对象或许对很多人听起来很恐怖.也很陌生,如果要说起EXEC_BAD_ACCESS异常,可能大家并不陌生.试图调用僵尸对象方法应用会崩溃(应用直接跳出),并抛出异常EXEC_BAD_A

iOS开发那些事-性能优化–查找和解决僵尸对象

内存泄漏是当一个对象或变量在使用完成后没有释放掉,那么如果我们走了另外一个极端情况会什么样呢?这就导致过渡释放(over release)问题,从而使对象"僵尸化",对象称为僵尸(zombies)对象.一个对象已经被释放过了,或者调用者没有这个对象的所有权而释放它,都会造成过渡释放,产生僵尸对象. 僵尸对象或许对很多人听起来很恐怖.也很陌生,如果要说起EXEC_BAD_ACCESS异常,可能大家并不陌生.试图调用僵尸对象方法应用会崩溃(应用直接跳出),并抛出异常EXEC_BAD_ACC

SQL Server-聚焦存储过程性能优化、数据压缩和页压缩提高IO性能(一)

前言 关于SQL Server基础系列尚未结束,还剩下最后一点内容未写,后面会继续.有园友询问我什么时候开始写SQL Server性能系列,估计还得等一段时间,最近工作也比较忙,但是会陆陆续续的更新SQL Server性能系列,本篇作为性能系列的基本引导,让大家尝尝鲜.在涉及到SQL Server性能优化时,我看到的有些文章就是一上来列出SQL Server的性能优化条例,根本没有弄清楚为什么这么做,当然也有可能是自己弄懂了,只是作为备忘录,但是到了我这里,我会遵循不仅仅是备忘录,还要让各位园友

MFC多线程复制数组的性能优化问题

问题描述 MFC多线程复制数组的性能优化问题 多线程复制数组,并且统计计算数组的方差和指数函数,使用MFC多线程优化的做法是什么? 解决方案 http://bbs.csdn.net/topics/330071067 解决方案二: 多线程性能及效率问题多线程性能及效率问题多线程性能及效率问题

论文摘抄 - Tenzing

本摘抄不保证论文完整性和理解准确性 背景 异构数据的适配及数据可扩展性,资源可扩展性,廉价机器,SQL查询. 架构概述 Worker pool,query server,clientinterfaces,metadata server Worker线程是long-running的,worker pool包括master节点和worker节点,以及一个master watcher. Query server把query解析,优化之后传给master执行,优化包括一些基本的规则优化和基于成本的优化.

mysql 索引B-Tree类型对索引使用的生效和失效情况详解

   当人们谈论索引的时候,如果没有特别指明类型 ,那多半说的是 B-Tree 索引,它使用B-Tree数据结构来存储数据.大多数 MySQL引擎都支持这种索引 .Archive引擎是 一个例外 :5.1 之前 Archive 不支持任何索引 ,直到 5.1 才开始支持单个自增列 ( A UTO INCREMENT ) 的索引. 我们使用术语"B-Tree " ,是因为 MySQL 在 CREATE TABLE 和其他语句中也使用该关键字 .   不过,底层的存储引擎也可能使用不同的存储结构,例

Windows 2000活动目录的优点

1. 基于策略的管理 活动目录的目录服务包括数据存储以及逻辑分层结构.逻辑结构为策略应用程序提供上下文分层结构.目录存储指定给特定上下文的策略(称为组策略).组策略表达一组业务规则,它包含应用于上下文的设置,它可确定对目录对象和域资源的访问.用户可使用哪些域资源(诸如应用程序),以及这些域资源是如何配置的.例如,组策略可确定用户登录后在计算机上可看到哪些应用程序,当 Microsoft SQL Server 在服务器上启动时,有多少用户可与其连接,以及当文档或服务移至不同部门或组时,用户可访问哪

Effective C#原则10:明白GetHashCode()的缺陷

这是本书中唯一一个被一整个函数占用的原则,你应该避免写这样的函数. GetHashCode()仅在一种情况下使用:那就是对象被用于基于散列的集合的关键 词,如经典的HashTable或者Dictionary容器.这很不错,由于在基类上实现的 GetHashCode()存在大量的问题.对于引用类型,它可以工作,但高效不高:对 于值类型,基类的实现经常出错.这更糟糕.你自己完全可以写一个即高效又正 确的GetHashCode().没有那个单一的函数比GetHashCode()讨论的更多,且令人 困惑

Windows 7系统加速需要掌握的五个方法

对于长时间使用XP的人来说刚刚接触Windows 7时会觉得Windows 7运行有些缓慢.其实这完全在于个人使用习惯.在这里将要为大家讲述加速一台Windows 7电脑的五大方法.这些修复和维护过程大多为电脑发烧友所普遍采用的做法,但是对于一般用户来说还是有很大帮助的.     1. 修改启动项程序     在你电脑上安装的许多软件和应用程序,都想把自己设置成每次随你的计算机一起启动.在某些情况下,在你登录进Windows之后,他们会立刻运行.其他时间他们便会在后台默默运行.无论哪种方式,这些