A12640 | Eating Soup
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The three friends, Kuro, Shiro, and Katie, met up again! It's time for a party...
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $n$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.
Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $m$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?
Could you help her with this curiosity?
You can see the examples and their descriptions with pictures in the "Note" section.
What the cats do when they unite? Right, they have a party. Since they wanted to have as much fun as possible, they invited all their friends. Now $n$ cats are at the party, sitting in a circle and eating soup. The rules are simple: anyone having finished their soup leaves the circle.
Katie suddenly notices that whenever a cat leaves, the place where she was sitting becomes an empty space, which means the circle is divided into smaller continuous groups of cats sitting next to each other. At the moment Katie observes, there are $m$ cats who left the circle. This raises a question for Katie: what is the maximum possible number of groups the circle is divided into at the moment?
Could you help her with this curiosity?
You can see the examples and their descriptions with pictures in the "Note" section.
输入格式
The only line contains two integers $n$ and $m$ ( $2 \leq n \leq 1000$ , $0 \leq m \leq n$ ) — the initial number of cats at the party and the number of cats who left the circle at the moment Katie observes, respectively.
输出格式
Print a single integer — the maximum number of groups of cats at the moment Katie observes.
输入输出样例
输入 #1
7 4
输出 #1
3
输入 #2
6 2
输出 #2
2
输入 #3
3 0
输出 #3
1
输入 #4
2 2
输出 #4
0
In the first example, originally there are $7$ cats sitting as shown below, creating a single group:
At the observed moment, $4$ cats have left the table. Suppose the cats $2$ , $3$ , $5$ and $7$ have left, then there are $3$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.
In the second example, there are $6$ cats sitting as shown below:
At the observed moment, $2$ cats have left the table. Suppose the cats numbered $3$ and $6$ left, then there will be $2$ groups remaining ( $\{1, 2\}$ and $\{4, 5\}$ ). It is impossible to have more than $2$ groups of cats remaining.
In the third example, no cats have left, so there is $1$ group consisting of all cats.
In the fourth example, all cats have left the circle, so there are $0$ groups.
At the observed moment, $4$ cats have left the table. Suppose the cats $2$ , $3$ , $5$ and $7$ have left, then there are $3$ groups remaining. It is possible to show that it is the maximum possible number of groups remaining.
In the second example, there are $6$ cats sitting as shown below:
At the observed moment, $2$ cats have left the table. Suppose the cats numbered $3$ and $6$ left, then there will be $2$ groups remaining ( $\{1, 2\}$ and $\{4, 5\}$ ). It is impossible to have more than $2$ groups of cats remaining.
In the third example, no cats have left, so there is $1$ group consisting of all cats.
In the fourth example, all cats have left the circle, so there are $0$ groups.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted