CF73A The Elder Trolls IV: Oblivon 题解

· · 题解

首先我们得求出某个长方形被切割后有多少块。 然后我们发现这题可以贪心,让本次步骤块数最多。 我们推断出来为了让每一个维度尽可能平均,所以可以/3。但某些维度的块数被限制住了,所以有些情况不能直接/3。

#include<iostream>
#include<algorithm>
using namespace std;
long long a[5],what,x1,y1,z1;
int main(){
    for(int i=1;i<=3;i++){
        cin>>a[i];
        a[i]--;
    }
    cin>>what;
    sort(a+1,a+4);
    if(what/3<=a[1]){
        x1=what/3;
        y1=(what-x1)/2;
    }
    else{
        x1=a[1];
        if((what-x1)/2<=a[2])y1=(what-x1)/2;
        else y1=a[2];
    } 
    if(what-y1-x1<=a[3])z1=what-y1-x1;
    else z1=a[3];
    cout<<(x1+1)*(y1+1)*(z1+1)/*<<" "<<x1<<" "<<y1<<" "<<z1*/;
    return 0;
}