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);
        }
    }


  • 相关阅读:
    微信公众平台开发(53)砸金蛋
    微信公众平台高级功能
    微信5.0安卓内测版下载
    微信公众平台2013.08.05更新说明
    淘宝微信互相屏蔽影响了谁
    WAP网页输入框的默认键盘类型控制
    如何通过微信创业赚钱
    腾讯风铃
    腾讯推出微信企业服务平台风铃
    一键生成HTML4和WAP站
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9053513.html
Copyright © 2011-2022 走看看