您的位置:首页 > 其它

The number of positions

2014-11-23 14:34 218 查看
Description

The number of positions

time limit per test: 0.5 second

memory limit per test: 256 megabytes

input: standard input

output: standard output

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 n, a and b (0 ≤ a, b < n ≤ 100).

Output
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-1;
if(c > b) {
r = b+1;
}else {
r = c+1;
}
printf("%d", r);
return 0;
}


Problem -124A - Codeforces

转载请注明出处:/article/5805443.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: