zoukankan      html  css  js  c++  java
  • e-olymp Problem8352 Taxi

    作为我在这个OJ玩了一下午的终结吧。

    水题一道,阅读理解OJ。

    传送门:点我

    Taxi

    At the peak hour, three taxi buses drove up at the same time, following one route, where the passengers immediately got crowded. The drivers found that the number of people in taxis is different, so they decided to relocate a part of passengers so that in each minibus there will be an equal number of passengers. Determine what is the fewest number of passengers have to be relocated at the same time.

    Input

    Three integers not greater than 100 - the number of passengers in the first, second and third taxi bus.

    Output

    Print one number - the minimum number of passengers that must be relocated. If its not possible, print the word IMPOSSIBLE (with capital letters).

    Time limit 1 second
    Memory limit 128 MiB
    Input example #1
    1 2 3
    
    Output example #1
    1

    题意:给定三个数,如果能均分那么输出最小的挪动个数,如果不能则输出IMPOSSIBLE。
    样例解释:1 2 3,把3挪一个到1,那么就变成了2 2 2,即均分。
    思路:如果和余3不等0,那么肯定不行。
    如果和余3等于0,直接看代码吧。。。。
    #include <cstdio>  
    #include <cstring>  
    #include <cmath>  
    #include <cstdlib>  
    #include <ctime>  
    #include <iostream>  
    #include <algorithm>  
    #include <sstream>  
    #include <string>  
    #include <vector>  
    #include <queue>  
    #include <stack>  
    #include <map>  
    #include <set>  
    #include <utility>  
    #include <bitset>  
    
    using namespace std;  
    #define LL long long  
    #define pb push_back  
    #define mk make_pair  
    #define pill pair<int, int>  
    #define REP(i, x, n)    for(int i = x; i <= n; ++i)
    int Scan()
    {
        int res = 0, ch, flag = 0;
        if((ch = getchar()) == '-')
            flag = 1;
        else if(ch >= '0' && ch <= '9')
            res = ch - '0';
        while((ch = getchar()) >= '0' && ch <= '9' )
            res = res * 10 + ch - '0';
        return flag ? -res : res;
    }
    int main(){
        int x,a[4];
        cin>>a[0]>>a[1]>>a[2];
        int sum = a[0]+a[1]+a[2];
        if(sum % 3 != 0){
            puts("IMPOSSIBLE");
        }else{
            sum = sum/3;
            int ans = 0;
            for(int i = 0 ; i < 3 ; i++){
                if(a[i] < sum) ans+=(sum-a[i]);
            }
            printf("%d
    ",ans);
        }
    }


  • 相关阅读:
    ASP.NET WebForm Best Practice 之ViewState
    我会为开源和自由学习,使用JAVA.但我决不会为了开源和自由放弃.NET
    EXT调用ASP.NET AJAX WebService
    我的2007
    博客园迎新春对联
    NBear.Mapping使用教程(2):NBear.Mapping的配置系统
    NBear.Mapping使用教程(3):第一个简单例子
    使用LumaQQ来开发QQ机器人
    解决方案迁移到Visual Studio 2008的一些相关问题
    NBear.Mapping使用教程(4):实体对象与ADO.NET对象的转换
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9053513.html
Copyright © 2011-2022 走看看