历届试题:约数与倍数卡片选择.pdfVIP

  • 1
  • 0
  • 约1.81千字
  • 约 3页
  • 2026-02-07 发布于北京
  • 举报

历届试题约数倍数选卡片

时间限制:1.0s内存限制:256.0MB

问题描述

闲暇时,福尔摩斯和玩一个游戏:

在N张卡片上写有N个整数。两人轮流拿走一张卡片。要求下一个人拿的数

字一定是前一个人拿的数字的约数或倍数。例如,某次福尔摩斯拿走的卡片上写

着数字“6”,则接下来可以拿的数字包括:

1,2,3,6,12,18,24

当轮到某一方拿卡片时,没有满足要求的卡片可选,则该方为输方。

请你利用计算机的优势计算一下,在已知所有卡片上的数字和可选哪些数字

的条件下,怎样选择才能保证必胜!

当选多个数字都可以必胜时,输出其中最小的数字。如果无论如何都会输,

则输出-1。

输入格式

输入数据为2行。第一行是若干空格分开的整数(每个整数介于1~100间),

表示当前剩余的所有卡片。

第二行也是若干空格分开的整数,表示可以选的数字。当然,第二行的数字

必须完全包含在第一行的数字中。

输出格式

程序则输出必胜的招法!!

样例输入

236

36

样例输出

3

样例输入

1223345

345

样例输出

4

PastExamQuestionsDivisorsand

MultipCardSelectionTimeLimit:1.0s

MemoryLimit:256.0MB

问题描述

Inhissparetime,HolmesysagamewithWatson:

NintegersarewrittenonNcards.Thetwoyerstaketurnspickingacard.The

nextyermustpickanumberthatiseitheradivisororamultipleofthenumber

pickedbythepreviousyer.Forexample,ifHolmespicksacardwiththenumber“6,”

thenthenumbersWatsoncanchoosefrominclude:

1,2,3,6,12,18,24

henitisayersturntopickacard,iftherearenocardsleftthatmeettherequirement,thatyerloses.

W

Pleaseusetheadvantageofyourcomputertocalculatehowtochoosethecardsto

ensureaguaranteedwin,givenallthenumbersonthecardsandtheavailablechoices!

Whenmultiplenumberscanguaranteeawin,outputthesmaltofthesenu

mbers.Ifthereisnowaytowin,output-1.

输入格式

Theinputdataconsistsof2lines.Thefirstlinecontainsseveralintegersseparated

byspaces(eachintegerisween1~100),representingalltheremainingcards.

Thesecondlinealsocontainsseveralintegersseparatedbyspaces,representingthenumbersthatcanbe

chosen.Ofcourse,thenumbersinthesecondlinemustbecompletelycontainedwithinthenumbersinthe

firstline.

输出格式

Theprogramshouldoutputthe

winningstrategy!!

样例输入

236

36

样例输出

3

样例输入

122334534

5

样例输出

4

文档评论(0)

1亿VIP精品文档

相关文档