【Codeforces Round #440 (Div. 2) C】 Maximum splitting

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

肯定用尽量多的4最好。 然后对4取模的结果 为0,1,2,3分类讨论即可

【代码】

#include <bits/stdc++.h>
using namespace std;

int fix(int x)
{
    int t = x/4;
    int rest = x%4;
    if (rest==0)
        return t;
    if (rest==1)
    {
        if (t>=2)
        {
            t-=2;
        }else
            return -1;
        t++;
        return t;
    }
    if (rest==2)
    {
        if (t>=1)
        {
            t--;
        }else return -1;
        t++;
        return t;
    }
    if (rest==3)
    {
        if (t>=3)
        {
            t-=3;
        }else return -1;
        t+=2;
        return t;
    }
}

int main()
{
    //freopen("F:\rush.txt","r",stdin);
    int q;
    scanf("%d",&q);
    for (int i = 1;i <= q;i++)
    {
        int x;
        scanf("%d",&x);
        printf("%d
",fix(x));
    }
    return 0;
}
原文地址:https://www.cnblogs.com/AWCXV/p/7673856.html