zoukankan      html  css  js  c++  java
  • The number of positions

    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。

    代码:

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 int main()
     5 {
     6     int n, a, b, c, r;
     7     scanf("%d%d%d", &n, &a, &b);
     8     c = n-a-1;
     9     if(c > b) {
    10         r = b+1;
    11     }else {
    12         r = c+1;
    13     }
    14     printf("%d", r);
    15     return 0;
    16 }

    Problem -124A - Codeforces

    转载请注明出处http://www.cnblogs.com/michaelwong/p/4116499.html

  • 相关阅读:
    作业3
    字符串的应用
    java类与对象
    作业
    水仙花数
    java例
    读书笔记(构建之法-11.19)
    补psp进度(11月4号-9号)
    PSP进度(11~16)
    团队项目-约跑软件需求规格说明书
  • 原文地址:https://www.cnblogs.com/michaelwong/p/4116499.html
Copyright © 2011-2022 走看看