(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;
} }
(Codeforce)The number of positions的更多相关文章
- (转载)Flash Number 数据类型
(转载)http://www.g168.net/txt/flash/learningactionscript/00001183.html Number 数据类型 Number 数据类型是双精度浮点数. ...
- java基础系列(一):Number,Character和String类及操作
这篇文章总结了Java中最基础的类以及常用的方法,主要有:Number,Character,String. 1.Number类 在实际开发的过程中,常常会用到需要使用对象而不是内置的数据类型的情形.所 ...
- LeetCode之旅(18)-Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...
- LeetCode(137) Single Number II
题目 Given an array of integers, every element appears three times except for one. Find that single on ...
- LeetCode(202) Happy Number
题目 Write an algorithm to determine if a number is "happy". A happy number is a number defi ...
- LeetCode之旅(17)-Ugly Number
题目: Write a program to check whether a given number is an ugly number. Ugly numbers are positive num ...
- LeetCode(306) Additive Number
题目 Additive number is a string whose digits can form additive sequence. A valid additive sequence sh ...
- LeetCode(65) Valid Number
题目 Validate if a given string is numeric. Some examples: "0" => true " 0.1 " ...
- (Codeforce)Correct Solution?
One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and g ...
随机推荐
- Vue-CLI 项目中相关操作
0830总结 Vue-CLI 项目中相关操作 一.前台路由的基本工作流程 目录结构 |vue-proj | |src | | |components | | | |Nav.vue | | |views ...
- Bran的内核开发教程(bkerndev)-02 准备工作
准备工作 内核开发是编写代码以及调试各种系统组件的漫长过程.一开始这似乎是一个让人畏惧的任务,但是并不需要大量的工具集来编写自己的内核.这个内核开发教程主要涉及使用GRUB将内核加载到内存中.GR ...
- PHP7源码之array_unique函数分析
以下源码基于 PHP 7.3.8 array array_unique ( array $array [, int $sort_flags = SORT_STRING ] ) (PHP 4 >= ...
- 前端深入之css篇丨初探【transform】,手把手带你实现1024程序员节动画
写在前面 马上就2020年了,不知道小伙伴们今年学习了css3动画了吗? 说起来css动画是一个很尬的事,一方面因为公司用css动画比较少,另一方面大部分开发者习惯了用JavaScript来做动画,所 ...
- opencv::卷积运算函数filter2D()
opencv::卷积运算函数filter2D() 使用掩模板矩阵(kernel)计算每个像素值 与原图相比,没有黑边 int main(int argc, char** argv) { Mat src ...
- HDU 3873 Invade the Mars(带限制条件的Dijkstra)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=3873 思路: 军队可以先等待在城市外面,等保护该城市的城市都被攻破后,直接进城(即进城不用耗费时间). ...
- 面试官,不要再问我“Java 垃圾收集器”了
如果Java虚拟机中标记清除算法.标记整理算法.复制算法.分代算法这些属于GC收集算法中的方法论,那么"GC收集器"则是这些方法论的具体实现. 在面试过程中这个深度的问题涉及的比较 ...
- 2.2 C语言_实现数据容器vector(排序功能)
上一节我们说到我们己经实现了一般Vector可以做到的自动扩充,告诉随机存取,那么现在我们需要完成vector的一个排序的功能. 排序算法我们网上一百度哇~~!很常见的就有8大排序算法: 1.选择排序 ...
- 微信小程序自定义弹窗(可通用)
效果图 .wxml <cover-view class='mask' wx:if='{{isShow}}'> <cover-view class='modal'> <co ...
- typescript 入门教程二
ts中面向对象成员修饰符:public , private , protexted(ts官方网站:ts) 在ts中,默认的成员修饰符就是public public:是表示是公开的,在任何地方,都可以调 ...