zoukankan      html  css  js  c++  java
  • CF190A:Vasya and the Bus(易错题) java程序员

    Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

    []   [Go Back]   [Status]  

    Description

    One day Vasya heard a story: "In the city of High Bertown a bus number 62 left from the bus station. It hadn grown-ups andm kids..."

    The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.

    The bus fare equals one berland ruble in High Bertown. However, not everything is that easy —no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with hisk (k > 0) children, pays overallk rubles: a ticket for himself and(k - 1) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.

    We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.

    Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.

    Input

    The input file consists of a single line containing two space-separated numbersn andm(0 ≤ n, m ≤ 105) — the number of the grown-ups and the number of the children in the bus, correspondingly.

    Output

    If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers — the minimum and the maximum possible total bus fare, correspondingly.

    Otherwise, print "Impossible" (without the quotes).

    Sample Input

    Input
    1 2
    
    Output
    2 2
    Input
    0 5
    
    Output
    Impossible
    Input
    2 2
    
    Output
    2 3

    Sample Output

    Hint

    In the first sample a grown-up rides with two children and pays two rubles.

    In the second sample there are only children in the bus, so the situation is impossible.

      In the third sample there are two cases:
    • Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total.
    • One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total.

    MYCode:

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    using namespace std;
    int main()
    {
        int n,m;
        while(scanf("%d%d",&n,&m) != EOF)
        {
            if(n==0)
            {
                if(m!=0)
                printf("Impossible\n");
                else
                printf("0 0\n");
                continue;
            }
            int mini,most;
            if(n>=m)
            mini=n;
            else
            mini=n+(m-n);
            if(m>=1)
            most=n+m-1;
            else
            most=n;
            //most=n+m-1;
            printf("%d %d\n",mini,most);
        }
    }

    //

    测试数据:
    0 0

    输出:0 0

    40 0

    输出:

    40 40

    注意考虑特殊情况,易错题目. 

  • 相关阅读:
    Java并发教程(Oracle官方资料)
    java中的字符集和编码
    一篇文章看懂Java并发和线程安全
    mysql中,如何查看数据库中当前可用的校勘?字符集默认的collation?
    mysql数据库中,查看当前支持的字符集有哪些?字符集默认的collation的名字?
    mysql数据库中,通过一条insert into语句,同时插入多个值
    jenkins第一次登陆,输入完密码之后,卡在了SetupWizard[jenkins]处
    mysql数据库,如何在登录mysql之后执行操作系统上的SQL脚本?
    mysql在命令行中,指定要连接的数据库?
    mysql中如何在命令行中,执行一个SQL脚本文件?
  • 原文地址:https://www.cnblogs.com/java20130725/p/3215896.html
Copyright © 2011-2022 走看看