zoukankan      html  css  js  c++  java
  • BZOJ 1024: [SCOI2009]生日快乐

    1024: [SCOI2009]生日快乐

    Time Limit: 1 Sec  Memory Limit: 162 MB

    Submit: 2967  Solved: 2157

    [Submit][Status][Discuss]

    Description

      windy的生日到了,为了庆祝生日,他的朋友们帮他买了一个边长分别为 X 和 Y 的矩形蛋糕。现在包括windy,一共有 N 个人来分这块大蛋糕,要求每个人必须获得相同面积的蛋糕。windy主刀,每一切只能平行于一块蛋糕的一边(任意一边),并且必须把这块蛋糕切成两块。这样,要切成 N 块蛋糕,windy必须切 N-1 次。为了使得每块蛋糕看起来漂亮,我们要求 N块蛋糕的长边与短边的比值的最大值最小。你能帮助windy求出这个比值么?

    Input

      包含三个整数,X Y N。1 <= X,Y <= 10000 ; 1 <= N <= 10

    Output

      包含一个浮点数,保留6位小数。

    Sample Input

    5 5 5

    Sample Output

    1.800000

    题解

    将一块x*y的蛋糕分成n份,要保证最后n份大小相同,所以要保证分开的两块蛋糕均为x*y/n的倍数,所以每一刀必须切在x/n或者y/n的倍数处。

    因为n<=10,所以直接dfs就可以了。

    代码

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<iostream>
    using namespace std;
    const int inf=0x3f3f3f3f;
    int n;
    double x,y;
    double dfs(double x,double y,int n){
    	double ans=inf;
    	if(n==1){
    		if(x<y)swap(x,y);
    		return x/y;
    	}
    	for(int i=1;i<=n/2;i++){
    		ans=min(ans,max(dfs(x/n*i,y,i),dfs(x-x/n*i,y,n-i)));
    		ans=min(ans,max(dfs(x,y/n*i,i),dfs(x,y-y/n*i,n-i)));
    	}
    	return ans;
    }
    int main(){
    	scanf("%lf%lf%d",&x,&y,&n);
    	printf("%.6lf
    ",dfs(x,y,n));
    	return 0;
    }
  • 相关阅读:
    Zigbee学习路线
    Zigbee简介
    验证lagrange 定理
    为什么(12)式,km不能直接相乘?而要让域k先乘一个代数A里面的单位元,再作用在群M上呢?
    strong weak distribution
    sufficient statistics
    tensorflow TypeError: Can not convert a float32 into a Tensor or Operation
    tensorflow 训练的时候loss=nan
    tensorflow run()和 eval()
    python array基本操作一
  • 原文地址:https://www.cnblogs.com/chezhongyang/p/7690567.html
Copyright © 2011-2022 走看看