bzoj1024 xingxing在努力 爆搜

  这道题的题意是给你一个矩形将他分成面积相等的n块矩形使得这n块矩形长边比短边的最大值最小, 我们注意到对于一个矩形有两种切法, 横切和纵切, 稍加思索我们可以发现切点肯定在1./c*k, k为正整数, 由此我们可以进行暴力搜索,代码如下:

#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

double dfs(double x, double y, int c)    //假设x>y 切成c块所需要的最大比
{
    if(x < y)  swap(x, y);        //保证x > y
    if(c == 1) return x/y;
    double r = 1.0/(double)c;
    double res = 10000000000000;
    for(int i=1; i<c; i++)
    {
        res = min(res, max(dfs(x*r*i, y, i), dfs(x-x*r*i, y, c-i)));
        res = min(res, max(dfs(x, y*r*i, i), dfs(x, y-y*r*i, c-i)));
    }
    return res;
}


int main()
{
    int x, y, z;
    while(scanf("%d%d%d", &x, &y, &z) == 3)
    {
        printf("%.6f\n", dfs(x, y, z));
    }
    return 0;
}

 

posted @ 2015-11-01 21:30  xing-xing  阅读(129)  评论(0)    收藏  举报