Bzoj 1024 scoi 2009 happy birthday

Source: Internet
Author: User

There is a piece of cake. The length is X and the width is Y. Now there are n people who want to divide the cake and ensure that the area of the cake is equal. Evaluate a method to minimize the maximum value of the ratio of the long side to the short side of all cakes.


Train of Thought: There is no idea for getting this question. But with a close eye, (n <= 10), amount .. It can be messed up...

You can directly search for water. Three parameters are passed to indicate the current length and width, and the current block needs to be divided into several parts, and then the water can pass through without worrying about it ..


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;}


Bzoj 1024 scoi 2009 happy birthday

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.