The number of positions
Description
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.
Sample test(s)
| input |
| 3 1 1 |
| output |
| 2 |
| input |
| 5 2 3 |
| output |
| 3 |
题解:Petr站在一个n人的队列里,已知站在他前面的人不少于a,站在他后面的人不多于b,求Petr站位的所有可能数目。
判断n-a和b的大小关系,如果前者大,考虑b,否则,考虑n-a。
代码:
#include <stdio.h>
#include <stdlib.h> int main()
{
int n, a, b, c, r;
scanf("%d%d%d", &n, &a, &b);
c = n-a-;
if(c > b) {
r = b+;
}else {
r = c+;
}
printf("%d", r);
return ;
}
The number of positions的更多相关文章
- Codeforces 124A - The number of positions
题目链接:http://codeforces.com/problemset/problem/124/A Petr stands in line of n people, but he doesn't ...
- 浙南联合训练赛 H - The number of positions
Petr stands in line of n people, but he doesn't know exactly which position he occupies. He can say ...
- A. The number of positions
A. The number of positions time limit per test 0.5 second memory limit per test 256 megabytes input ...
- (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 ...
- [LeetCode] Total Hamming Distance 全部汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- [LeetCode] Hamming Distance 汉明距离
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Total Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- Hamming Distance
The Hamming distance between two integers is the number of positions at which the corresponding bits ...
- 461. Hamming Distance and 477. Total Hamming Distance in Python
题目: The Hamming distance between two integers is the number of positions at which the corresponding ...
随机推荐
- C++容器在遍历时的删除问题
容器是非常便捷常用的,经常用容器来存储多条数据,然后对数据进行增删查改. 有时要在遍历的同时删除一条数据,但是这样删除的时候程序会导致程序崩溃. 这个问题在GCC 中不会出现,而在VS2008,VS2 ...
- Python基础:11.2_函数调用
我们已经接触过函数(function)的参数(arguments)传递.当时我们根据位置,传递对应的参数.这种参数传递的方式被称为函数参数的位置传递. 我们将接触更多的参数传递方式. 回忆一下位置传递 ...
- 关于google CDN 在中国访问不了的解决办法
因原网站的script部分使用了google CDN,导致在中国看不了跟google相关的所有东西 解决方法: 得把google CDN 连接改成其他公司的CDN 例: 修改前:<script ...
- Git 详细命令集
初始化一个Git仓库,使用git init命令. 添加文件到Git仓库,分两步: 第一步,使用命令git add <file>,注意,可反复多次使用,添加多个文件: 第二步,使用命令git ...
- js数组(二)
一.位置方法 indexOf()和laseIndexOf() indexOf是从数组的第0项开始向后查找,没有找到返回-1,要求使用=== var numbers = [1,2,3,4,5,4,3,2 ...
- Criteria 和 DetachedCriteria的区别与使用(转)
转自:http://javapub.iteye.com/blog/1149709 Criteria 和 DetachedCriteria 的主要区别在于创建的形式不一样, Criteria 是在线的, ...
- Oracle字符编码
.检查服务器编码: 执行SQL语法: Java代码 select * from v$nls_parameters; 或 Java代码 select * from nls_database_parame ...
- 旧的VirtualBox News(从1.3.4开始)
https://linuxtoy.org/archives.html https://linuxtoy.org/archives/virtualbox-134.html http://www.cnbl ...
- Android 使用PopupWindow实现弹出菜单
在本文当中,我将会与大家分享一个封装了PopupWindow实现弹出菜单的类,并说明它的实现与使用. 因对界面的需求,android原生的弹出菜单已不能满足我们的需求,自定义菜单成了我们的唯一选择,在 ...
- LINQpad 用法汇总
// C# Expression //Courses // .Join ( // CourseSections, // course => course.CourseId, // section ...