- 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
您可能关注的文档
最近下载
- 辽宁省沈阳市2026届九年级上学期期末练习物理试卷.pdf VIP
- 关睢、蒹葭原文及翻译.doc VIP
- DB31_T 1648-2025 元器件抗辐射性能评估指南.docx VIP
- 圆锥曲线高考大题第一类题型弦长面积问题.pdf VIP
- DB31_T 1649-2025 蓝莓栽培技术规程.docx VIP
- DB31_T 1650-2025 新杨黑羽蛋鸡配套系.docx VIP
- 诸暨市茅渚埠桥加维修工程.doc VIP
- 标准图集-14SG313-老虎窗-采光井-地下车库坡道式出入口.pdf VIP
- 《运输实务》教学教案(全).docx VIP
- 《煤矿安全生产条例》考试题库及答案.docx VIP
原创力文档

文档评论(0)