NC20272 生日快乐(dfs)

这题题目的重要信息就是n很小并且面积要相等

因为每次都要切断,我们每次切割完的蛋糕一定要平分成功,因此我们每次切都要按x/n的倍数切

这个n代表当前这块蛋糕要分为几块,并且切完的两块蛋糕,每个蛋糕要分为几块也是固定的,因为面积要相等。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int N=1e5+10;
const int inf=0x3f3f3f3f;
double dfs(double x,double y,int n){
    if(n==1){
        return max(x,y)/min(x,y);
    }
    double res=1e18;
    for(int i=1;i<n;i++){
        double tmp1=max(dfs(x/n*i,y,i),dfs(x/n*(n-i),y,n-i));
        double tmp2=max(dfs(x,y/n*i,i),dfs(x,y/n*(n-i),n-i));
        res=min(res,min(tmp1,tmp2));
    }
    return res;
}
int main(){
    //ios::sync_with_stdio(false);
    int x,y;
    int n;
    cin>>x>>y>>n;
    printf("%.6f\n",dfs(x,y,n));
    return 0;
}
View Code

 

posted @ 2021-02-21 15:08  朝暮不思  阅读(42)  评论(0编辑  收藏  举报