您的位置:首页 > 其它

BZOJ 1024 SCOI 2009 生日快乐 深搜

2016-02-26 10:48 375 查看
题目大意:有一块蛋糕,长为X,宽为Y。如今有n个人来分这块蛋糕,还要保证每一个人分的蛋糕的面积相等。求一种分法,使得全部的蛋糕的长边与短边的比值的最大值最小。

思路:刚拿到这个题并没有什么思路。可是定睛一看。(n <= 10),额。。能够乱搞了。。。

直接爆搜就能够水过。传三个參数,代表当前的长和宽,还有当前块须要被分成几块,然后随便乱搞就能够水过了。。

CODE:

#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;

int X,Y,cnt;

double DFS(double x,double y,int step);

int main()
{
cin >> X >> Y >> cnt;
cout << fixed << setprecision(6) << DFS(X,Y,cnt) << endl;
return 0;
}

double DFS(double x,double y,int step)
{
if(step == 1) {
if(x < y)	swap(x,y);
return x / y;
}
double _x = x / step,re = 10000.0;
for(int i = 1;i < step; ++i) {
double temp = DFS(_x * i,y,i);
temp = max(temp,DFS(x - _x * i,y,step - i));
re = min(re,temp);
}
double _y = y / step;
for(int i = 1;i < step; ++i) {
double temp = DFS(x,_y * i,i);
temp = max(temp,DFS(x,y - _y * i,step - i));
re = min(re,temp);
}
return re;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: