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\n",ans);
    }
}


posted on 2018-05-17 21:50  Esquecer  阅读(177)  评论(0编辑  收藏  举报

导航