A1206 | [COCI-2010_2011-contest4]#4 HRPA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko and Slavko’s favourite pastime is competing against each other in mathematical games. This time they took a heap of N pebbles and settled on the following rules:
1. Mirko is the first to play, then Slavko, then Mirko again, then Slavko and so on;
2. Mirko can take any number of pebbles (between 1 and N, inclusive) from the heap during his first move;
3. In each of the following turns the current player must take at least 1 pebble and is allowed to take at most double the amount of pebbles taken during the previous turn by the other player; naturally, one cannot take more pebbles than the remaining amount in the heap;
4. The player who takes the last pebble is the winner.
Both Mirko and Slavko play optimally (if it is possible for one player to beat the other, that player will always win). We need to find the minimum number of pebbles that Mirko must take during his first turn such that he is guaranteed to win the game.
1. Mirko is the first to play, then Slavko, then Mirko again, then Slavko and so on;
2. Mirko can take any number of pebbles (between 1 and N, inclusive) from the heap during his first move;
3. In each of the following turns the current player must take at least 1 pebble and is allowed to take at most double the amount of pebbles taken during the previous turn by the other player; naturally, one cannot take more pebbles than the remaining amount in the heap;
4. The player who takes the last pebble is the winner.
Both Mirko and Slavko play optimally (if it is possible for one player to beat the other, that player will always win). We need to find the minimum number of pebbles that Mirko must take during his first turn such that he is guaranteed to win the game.
输入格式
The first and only line of input contains the positive integer N (2 ≤ N ≤ 10^15), the number of pebbles in the starting heap.
输出格式
The first and only line of output must contain the required minimum number of pebbles that Mirko needs to remove during his first turn.
输入输出样例
输入 #1
4
输出 #1
1
输入 #2
7
输出 #2
2
输入 #3
8
输出 #3
8
First sample description:
Mirko has 4 possibilities to choose from: he can take 1, 2, 3, or 4 pebbles from the heap. If he takes all
4 pebbles he will naturally win, but that is not the minimum solution. We need to check the remaining
alternatives. If Mirko takes only one pebble, Slavko is left with a heap of 3, but he can take at most 2.
Slavko cannot take all pebbles, but Mirko will be able to take all remaining pebbles during his next turn,
winning the game. We conclude that 1 is the minimum solution for this test case.
Mirko has 4 possibilities to choose from: he can take 1, 2, 3, or 4 pebbles from the heap. If he takes all
4 pebbles he will naturally win, but that is not the minimum solution. We need to check the remaining
alternatives. If Mirko takes only one pebble, Slavko is left with a heap of 3, but he can take at most 2.
Slavko cannot take all pebbles, but Mirko will be able to take all remaining pebbles during his next turn,
winning the game. We conclude that 1 is the minimum solution for this test case.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted