文档下载 文档下载导航
设为首页 | 加入收藏
搜索 请输入内容:  
 导航当前位置: 文档下载 > 所有分类 > IT/计算机 > sorting or searching 算法竞赛入门经典 刘汝佳
侵权投诉

sorting or searching 算法竞赛入门经典 刘汝佳

这个资料对正在看《算法竞赛入门经典》这本书的人有用。事实上,对一切学算法的人都有用。这是来自uva online judge的题目,也即刘汝佳《算法竞赛入门经典》这本书上的习题。文档已排版好。适合打印下来,不用天天盯着电脑。电脑也并不是总在身边。

Sorting or searching

340 - Master-Mind HintsMasterMind 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

Sample Output

Game 1:

(1,1)

第1页

你可能喜欢

  • 算法入门
  • 经典算法
  • 路由算法
  • 密码算法
  • 算法交易
  • 组合算法
  • 算法报告

热门文档

相关文档

  • lists 算法竞赛入门经典 刘汝佳

    lists 算法竞赛入门经典 刘汝佳_IT/计算机_专业资料。这个资料对正在看《算法...Where a card may be moved either one position to the left or three ...

  • 算法竞赛-入门经典-作者刘汝佳

    算法竞赛-入门经典-作者刘汝佳_韩语学习_外语学习_教育专区。算法竞赛入门经典...(1) #include<stdio.h> /* do NOT use this if x is very large or ...

  • 算法竞赛-入门经典-作者刘汝佳

    算法竞赛-入门经典-作者刘汝佳_IT/计算机_专业资料。算法竞赛-入门经典-作者刘汝佳 (《算法竞赛入门经典》)算法竞赛-入门经典-作者刘汝佳.doc 第 1 部分第1章...

  • 刘汝佳《算法入门经典》答案

    刘汝佳《算法入门经典》答案_计算机软件及应用_IT/计算机_专业资料。刘汝佳《...[删除] 标签: 分类: 算法竞赛入门经典杂谈 7.1 简单枚举 7.1.1 除法输入...

  • big number 算法竞赛入门经典 刘汝佳

    big number 算法竞赛入门经典 刘汝佳_IT/计算机_专业资料。这个资料对正在看《...A sign (division or mod). Again spaces. And another input number. Both ...

  • 算法竞赛-入门经典-作者刘汝佳

    算法竞赛-入门经典-作者刘汝佳_计算机软件及应用_IT/计算机_专业资料。算法竞赛...(1) #include<stdio.h> /* do NOT use this if x is very large or ...

  • 刘汝佳 算法竞赛入门经典授课教案第2章_循环结构程序设计

    刘汝佳 算法竞赛入门经典授课教案第2章_循环结构程序设计_IT认证_资格考试/认证_教育专区。第2章 循环结构程序设计 刘汝佳 第2章 循环结构程序设计 【教学内容...

  • 算法竞赛入门经典授课教案第3章_数组和字符串(精心排版...

    算法竞赛入门经典授课教案... 33页 2财富值 刘汝佳 算法竞赛入门经典授...... 算法竞赛入门经典授课教案第3章_数组和字符串(精心排版,并扩充部分内容) 非常...

  • 刘汝佳-6数据结构入门

    刘汝佳基础数据结构 97页 免费 《算法竞赛入门经典》 16页 免费 数据结构(C...分析 ?行:中位数 or 平均数? ?列?(请思考) ? 中位数如何求? ? 快速排序...

站点地图 | 文档上传 | 侵权投诉 | 手机版
本站所有资源均来自互联网,本站只负责收集和整理,均不承担任何法律责任,如有侵权等其它行为请联系我们.
文档下载 Copyright 2013 doc.guandang.net All Rights Reserved.  -  email