(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.
The only line contains three integers n, a and b (0≤a,b<n≤100).
Print the single number − the number of the sought positions.
3 1 1
2
5 2 3
3
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:
#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+;
}
else if(a>=n)
{
cout << ;
}
else
{
cout << n-a;
} }
最新文章
- Python开发入门与实战18-Windows Azure 虚拟机部署
- 移动终端学习2:触屏原生js事件及重力感应
- 【jsp+jpa】Check your ViewResolver setup!
- 在 windows 上面安装 tensorflow
- NET Core 整合Autofac和Castle
- .net web 开发平台- 表单设计器 一(web版)
- 关机和重启Linux命令
- cesium自定义气泡窗口infoWindow后续优化篇
- MATLAB中绘制图形的时候,坐标和标题倒置
- 在VS 2017 下创建 Xamarin NuGet Package
- 点火开关分为4个档位,分别是off,acc,IG-on,和ST
- 导入另一个 Git库到现有的Git库并保留提交记录
- XX-net
- Azure 中 Windows 虚拟机的大小
- Nginx反向代理下IIS获取真实IP
- win10 uwp unix timestamp 时间戳 转 DateTime
- [并查集] 1107. Social Clusters (30)
- LeetCode-330.Patching Array
- 【总结】2017年当下最值得你关注的前端开发框架,不知道你就OUT了!
- ORB-SLAM(十二)优化