我是靠谱客的博主 喜悦发卡,这篇文章主要介绍(Codeforce)The number of positions,现在分享给大家,希望可以做个参考。

 

Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say that there are no less than a people standing in front of him and no more than b people standing behind him. Find the number of different positions Petr can occupy.

Input

The only line contains three integers na and b (0≤a,b<n≤100).

Output

Print the single number − the number of the sought positions.

Examples
Input
复制代码
1
3 1 1
Output
复制代码
1
2
Input
复制代码
1
5 2 3
Output
复制代码
1
3
Note

The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).

In the second sample they are 3, 4 and 5.

简单翻译就是排队,三个输入,一个是队伍的人数n,一个是在排在他前面不能少于a的人,另一个是排在他后面不多于b的人

输出: 他可以站的位置。 

可以看第一个case input 3 1 1     他可以站2  他前面有1个人后面1个人  他可以站3 前面2个人后面没有人

idea :

1.当a>=n,则肯定没有位置供选择 则输出0

2.当a+b==n时,我们可以发现我们所能选的就是从a开始到n结束  即b个位置

3.当a+b<n时,我们可以从n-b开始到n  考虑端点就是b+1个嘛

4.当a+b>n时 且a<n,我们可以从a+1开始取,取到n,就是n-a个位置

AC:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream> #include <algorithm> using namespace std; int main() {   int n,a,b;   cin >> n >> a >> b;   if(a+b==n)   {     cout << b;   }   else if(a+b<n)   {     cout << b+1;   }      else if(a>=n)   {     cout << 0;   }   else   {     cout << n-a;   } }
View Code

 

 

 

 

转载于:https://www.cnblogs.com/jmzIT/p/10199583.html

最后

以上就是喜悦发卡最近收集整理的关于(Codeforce)The number of positions的全部内容,更多相关(Codeforce)The内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(64)

评论列表共有 0 条评论

立即
投稿
返回
顶部