现在的位置: 首页 > 综合 > 正文

BZOJ 1024 SCOI 2009 生日快乐 深搜

2018年01月19日 ⁄ 综合 ⁄ 共 742字 ⁄ 字号 评论关闭

题目大意:有一块蛋糕,长为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;
}

抱歉!评论已关闭.