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


  • 相关阅读:
    Maven打包时过滤测试代码或指定特定的测试类(maven-surefire-plugin)
    Maven项目配置外部依赖(本地依赖)
    手把手教你创建「人物角色Persona」
    微服务与Docker介绍
    深入学习微框架:Spring Boot
    技术干货:我们的项目是如何技术选型的
    为什么选择Spring Boot作为微服务的入门级微框架
    Android Material Design 兼容库的使用详解
    Android 实现QQ、微信、新浪微博和百度第三方登录
    Android ijkplayer详解使用教程
  • 原文地址:https://www.cnblogs.com/Esquecer/p/9053513.html
Copyright © 2011-2022 走看看