Bzoj1024 [scoi2009] Happy birthday

Source: Internet
Author: User

Questions: Make up your brain.


Idea: a binary answer.

But how to judge?

We define whether the recursive function judge (a, B, k) can be divided into k blocks for a cake with a length of A and B.

Each time, we only need to enumerate the division method, that is, the number of blocks and the number of blocks are divided into two parts, vertical cutting or vertical.

If k = 1, the system returns the result.

In this example, the current binary answer mid is used as the parameter.

In this way, you can.


Code:

#include <cstdio>#include <cstring>#include <cctype>#include <iostream>#include <algorithm>using namespace std;typedef double f2;int n;f2 ans, area;#define git(a, b) ((a)>(b)?(a)/(b):(b)/(a))bool dfs(f2 x, f2 y, f2 k) {if (k == 1)return git(x, y) <= ans;int i;for(i = 1; i < k; ++i)if (dfs(x, i * area / x, i) && dfs(x, y - i * area / x, k - i))return 1;for(i = 1; i < k; ++i)if (dfs(i * area / y, y, i) && dfs(x - i * area / y, y, k - i))return 1;return 0;}int main() {int x, y;scanf("%d%d%d", &x, &y, &n);area = x * y / (f2)n;f2 L = 0, R = 10000, mid;while(R - L > 1e-8) {mid = (L + R) / 2;ans = mid;if (dfs(x, y, n))R = mid;elseL = mid;}printf("%.6lf", L);return 0;}


Bzoj1024 [scoi2009] 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.