CF98B.Help King
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive.
Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, but not happily ever after: one day a vicious dragon attacked the kingdom and stole Victoria. The King was full of grief, yet he gathered his noble knights and promised half of his kingdom and Victoria's hand in marriage to the one who will save the girl from the infernal beast.
Having travelled for some time, the knights found the dragon's lair and all of them rushed there to save Victoria. Each knight spat on the dragon once and, as the dragon had quite a fragile and frail heart, his heart broke and poor beast died. As for the noble knights, they got Victoria right to the King and started brawling as each one wanted the girl's hand in marriage.
The problem was that all the noble knights were equally noble and equally handsome, and Victoria didn't want to marry any of them anyway. Then the King (and he was a very wise man and didn't want to hurt anybody's feelings) decided to find out who will get his daughter randomly, i.e. tossing a coin. However, there turned out to be n noble knights and the coin only has two sides. The good thing is that when a coin is tossed, the coin falls on each side with equal probability. The King got interested how to pick one noble knight using this coin so that all knights had equal probability of being chosen (the probability in that case should always be equal to 1 / n). First the King wants to know the expected number of times he will need to toss a coin to determine the winner. Besides, while tossing the coin, the King should follow the optimal tossing strategy (i.e. the strategy that minimizes the expected number of tosses). Help the King in this challenging task.
这是官方比赛期间所用题目的修改版本。遗憾的是,原题作者的解法被发现是错误的,因此本题特别为题库存档而进行了修改。
很久以前,在一个遥远的王国里住着一位国王。国王有一位美丽的女儿——维多利亚。他们原本生活得十分幸福,但并非从此永远幸福:某天,一条凶恶的巨龙袭击了王国,并掳走了维多利亚。国王悲痛欲绝,但仍召集了他忠诚的骑士们,并许诺——谁能从这地狱般的怪兽手中救回公主,便将王国的一半疆土与维多利亚的芳心一并赐予他。
骑士们经过一番跋涉,终于找到了巨龙的巢穴,于是全体奋勇冲入营救维多利亚。每位骑士都朝巨龙吐了一口唾沫;由于这条巨龙的心脏极其脆弱,它的心脏当场破裂,可怜的怪兽就此死去。而英勇的骑士们则顺利地将维多利亚护送回国王面前——然而,随即他们便开始激烈争执,因为每个人都想迎娶这位公主。
问题在于:所有骑士同样高贵、同样英俊,而维多利亚本人却根本不想嫁给其中任何一人。此时,国王(他是一位非常睿智的人,不愿伤害任何人的感情)决定通过随机方式来选定驸马,即抛掷一枚硬币。然而,现场共有 $ n $ 位高贵的骑士,而硬币仅有正反两面。值得庆幸的是,每次抛掷硬币时,正反两面朝上的概率完全相等。国王由此产生了一个疑问:如何仅借助这枚硬币,公平地选出一位骑士(即每位骑士被选中的概率严格等于 $ \frac{1}{n} $)?首先,国王希望知道:为确定最终胜出者,他期望需要抛掷硬币多少次?此外,在抛掷过程中,国王必须采用最优策略(即能使期望抛掷次数最小化的策略)。请帮助国王完成这项富有挑战性的任务。
输入格式
The first line contains a single integer n from the problem's statement (1 ≤ n ≤ 10000).
第一行包含题目描述中的单个整数 n(1 ≤ n ≤ 10000)。
输出格式
Print the sought expected number of tosses as an irreducible fraction in the following form: "a/b" (without the quotes) without leading zeroes.
以最简分数形式输出所求的期望投掷次数,格式为:“a/b”(不带引号),且 a 和 b 均无前导零。
输入输出样例
输入#1
2
输出#1
1/1
输入#2
3
输出#2
8/3
输入#3
4
输出#3
2/1
输入解题思路,AI测评打分。不知道怎么写?