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 ...
随机推荐
- Ext.grid.GridPanel的属性
1.Ext.grid.GridPanel 主要配置项: store:表格的数据集 columns:表格列模式的配置数组,可自动创建ColumnModel列模 ...
- iOS self和super的区别
self和super的区别 #import <Foundation/Foundation.h> 首先先写两个类 fist和two,two继承fist类 @interface First:N ...
- hdu1867A + B for you again
Problem Description Generally speaking, there are a lot of problems about strings processing. Now yo ...
- java之认识基本数据类型及其封装类装箱和拆箱总结
由于在java中,数据类型总共可分为两大种,基本数据类型和引用数据类型.基本类型的数据不是对象,所以对于要将数据类型作为对象来使用的情况,java提供了相对应的包装类.对于8种数据类型的总结如下: 自 ...
- 【转】unity3d的常用快捷键
Unity3D默认的快捷键. shift +方向键 向“向方向键前进” Windows系统Unity3D中的快捷键 组合键 键 功能 File 文件 Ctrl N New ...
- dialog获取焦点
弹出层是一个iframe openWindow:function (options) { var url = options.url; url += url.indexOf("?" ...
- docker 容器扩盘
docker:/root/sbin# cat add_fs.sh #!/bin/bash #This script is dynamic modify docker container disk #A ...
- 只有电信3G是公网ip。
只有电信3G是公网ip,其它网络拿到是内部网.
- Java中,当表单含有文件上传时,提交数据的如何读取
http://blog.csdn.net/lian_zhihui1984/article/details/6822201
- 并查集及其简单应用:优化kruskal算法
并查集是一种可以在较短的时间内进行集合的查找与合并的树形数据结构 每次合并只需将两棵树的根合并即可 通过路径压缩减小每颗树的深度可以使查找祖先的速度加快不少 代码如下: int getfather(i ...