生日快乐

[SCOI2009]生日快乐

https://ac.nowcoder.com/acm/problem/20272

思路:直接根据题意爆搜(dfs)就可以了。
代码如下:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
double x,y;
int n;
double dfs(double x,double y,int cnt){
    if(cnt==1){
        if(x<y) swap(x,y);      //long / short
        return x/y;
    }
    double minn=10000.0,maxx=0.0;
    double xx=x/cnt,yy=y/cnt;
    for(int i=1;i<cnt;i++){
        maxx=dfs(x-xx*i,y,cnt-i);
        maxx=max(maxx,dfs(xx*i,y,i));
        minn=min(maxx,minn);
    }
    for(int i=1;i<cnt;i++){
        maxx=dfs(x,y-yy*i,cnt-i);
        maxx=max(maxx,dfs(x,yy*i,i));
        minn=min(maxx,minn);
    }
    return minn;
}
int main()
{
    scanf("%lf %lf %d",&x,&y,&n);
    printf("%.6f\n",dfs(x,y,n));
}
全部评论

相关推荐

03-16 22:00
武汉大学 C++
幸福的小熊猫想要offer:我阿里投的 c++岗,面试官说自己是做 java 的,c++这辈子才有了
点赞 评论 收藏
分享
04-17 18:32
门头沟学院 Java
野猪不是猪🐗:他跟你一个学校,你要是进来之后待遇比他好,他受得了?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务