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


  • 相关阅读:
    tracert命令与tracert (IP地址)-d有什么区别?
    linux下通过进程名查看其占用端口
    Union和Union All的区别
    外连接、内连接
    Linux 删除文件夹和文件的命令(强制删除包括非空文件)
    linux查看当前目录
    Linux chmod命令及权限含义
    MySQL的if,case语句
    case when
    java生成验证码图片
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9053513.html
Copyright © 2020-2023  润新知