Bzoj 1024 Happy Birthday scoi2009

Source: Internet
Author: User

No idea ......

However, because each cake has the same area and must be cut into two halves each time, the area of each half is a multiple of the area of each cake.

Calculate the number of cut-down cakes, calculate the cut place, divide X and Y, and perform recursive search.

Code:

#include <cstdio>#include <cstring>#include <cstdlib>#include <iostream>#include <algorithm>#include <cmath>#define inf 0x7f7f7f7fusing namespace std;int num;double X, Y;double dfs(int n, double x, double y){    if (n == 1) return max(x, y) / min(x, y);    double d = (double)n;    double ans = inf;    for (int i = 1; i < n; ++i)    {        ans = min(ans, max(dfs(i, x/d*i, y), dfs(n-i, x/d*(n-i), y)));        ans = min(ans, max(dfs(i, x, y/d*i), dfs(n-i, x, y/d*(n-i))));    }    return ans;}int main(){    scanf("%lf%lf%d", &X, &Y, &num);    printf("%lf\n", dfs(num, X, Y));    return 0;}

 

Bzoj 1024 Happy Birthday scoi2009

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.