• Brute Force


    B. Candy Boxes 

    Problem's Link:   http://codeforces.com/contest/488/problem/B


    Mean: 

    T题目意思很简单,不解释。

    analyse:

    这道题还是很有意思的,需要考虑到各种情况才能AC。

    解这个题目之前,首先要推出两条式子

      x4=3x1
      4x1=x2+x3

    然后就是分类讨论,枚举各种情况就可。

    Time complexity: O(1)

    Source code: 

    //  Memory   Time
    //  1347K     0MS
    //   by : Snarl_jsb
    //   2014-11-26-21.20
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<iostream>
    #include<vector>
    #include<queue>
    #include<stack>
    #include<map>
    #include<string>
    #include<climits>
    #include<cmath>
    #define N 1000010
    #define LL long long
    using namespace std;
    
    int ans[10], input[10];
    bool flag = true;
    bool Solve(int n)
    {
        if (n == 0)
        {
            puts("YES");
            printf("%d
    %d
    %d
    %d
    ", 1, 1, 3, 3);
        }
        if (n == 1)
        {
            puts("YES");
            ans[1] = input[1], ans[4] = ans[1] * 3, ans[2] = ans[1], ans[3] = ans[4];
            for (int i = 2; i <= 4; i++) printf("%d
    ", ans[i]);
        }
        if (n == 2)
        {
            if (input[2] % 3)
            {
                if (input[1] * 3 < input[2]) return flag = false;
                puts("YES");
                ans[1] = input[1], ans[4] = ans[1] * 3;
                int tmp = 4 * ans[1] - input[2];
                printf("%d
    %d
    ", ans[4], tmp);
            }
            else
            {
                if (input[2] / 3 > input[1]) return flag = false;
                puts("YES");
                ans[1] = input[2] / 3;
                int tmp = 4 * ans[1] - input[1];
                printf("%d
    %d
    ", ans[1], tmp);
            }
        }
        if (n == 3)
        {
            if (input[3] % 3)
            {
                if (input[1] * 3 < input[3]) return flag = false;
                for (int i = 1; i <= 3; i++) ans[i] = input[i];
                ans[4] = ans[1] * 3;
                if (4 * ans[1] != ans[2] + ans[3]) return flag = false;
                puts("YES");
                printf("%d
    ", ans[4]);
            }
            else
            {
                if (input[3] / 3 > input[1]) return flag = false;
                if (input[3] / 3 == input[1])
                {
                    puts("YES");
                    printf("%d
    ", input[1] * 4 - input[2]);
                    return true;
                }
                ans[1] = input[3] / 3, ans[4] = input[3], ans[2] = input[1], ans[3] = input[2];
                if (4 * ans[1] != ans[2] + ans[3]) return flag = false;
                puts("YES");
                printf("%d
    ", ans[1]);
            }
        }
        if (n == 4)
        {
            for (int i = 1; i <= 4; i++) ans[i] = input[i];
            if (4 * ans[1] == ans[2] + ans[3]) puts("YES");
            else flag = false;
        }
    }
    
    int main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
    //    freopen("C:\Users\ASUS\Desktop\cin.cpp","r",stdin);
    //    freopen("C:\Users\ASUS\Desktop\cout.cpp","w",stdout);
        int n, i, j;
        scanf("%d", &n);
        for (i = 1; i <= n; i++) scanf("%d", &input[i]);
        sort(input + 1, input + n + 1);
        Solve(n);
        if (!flag)
        {
            puts("NO");
            return 0;
        }
        return 0;
    }
    /*
    
    */
    

      

  • 相关阅读:
    Android Butterknife(黄油刀) 使用方法总结【转】
    Andriod- 一些包
    Andriod- 学习网站
    Android热点 8.0 ,7.1 ,6.0一7.0 以及6.0以下热点创建到连接完全适配
    Android- 动态修改ToolBar的Menu菜单
    C#- Socket实现服务器与多个客户端通信
    html使用pdf.js途中遇到的坑和坑
    小程序内嵌H5页面和小程序内部页面互相传参和内嵌H5页面的调试
    记录一次Centos7宕机事件
    Spring Boot 2.x实战
  • 原文地址:https://www.cnblogs.com/crazyacking/p/4124972.html
Copyright © 2020-2023  润新知