lightoj 1297(三分)

传送门:Largest Box

题意:长度为L宽度为W的纸四个角去掉x*x的正方形,然后形成一个长方体,问能组成长方体的最大体积为多少。

分析:三分x求最值。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#define N 100010
#define mod 1000000007
#define LL long long
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const double eps=1e-8;
double L,W;
double calc(double x)
{
    return (L-2*x)*(W-2*x)*x;
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lf%lf",&L,&W);
        double l=0,r=min(L,W)/2.0,mid,mmid;
        while(l<r)
        {
            mid=(l+r)/2.0;
            mmid=(mid+r)/2.0;
            if(calc(mid)<=calc(mmid))l=mid+eps;
            else r=mmid-eps;
        }
        printf("Case %d: %.10lf\n",cas++,calc(mid));
    }
}

时间: 2024-07-31 04:21:07

lightoj 1297(三分)的相关文章

Lightoj 1297 - Largest Box

Memory Limit: 32 MB In the following figure you can see a rectangular card. Thewidth of the card isW and length of the card is L and thicknessis zero. Four(x*x) squares are cut from the four corners of the cardshown by the black dotted lines. Then th

LightOJ 1030 Discovering Gold【概率】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题意:基础概率题. 代码: #include <stdio.h> #include <string.h> #include <vector> #include <string> #include <algorithm> #include <iostream> #include <iterator>

LightOJ - 1370 Bi-shoe and Phi-shoe

题目链接:http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1370 题目大意:给N个数a[i], N <= 1e6,问使 Φ(x) >= a[i] 成立的最小x的所有x的和是多少. 解题思路:我们知道的是对于素数 m 来说,phi[m] = m - 1.另一方面,对于一个合数 m 来说, phi[m] < phi[x] , x > m && x 是素数. 因此,我们可以认为,每

lightoj 1057 - Collecting Gold(状压dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1057 题解:看似有点下记忆话搜索但是由于他是能走8个方向的也就是说两点的距离其实就是最大的x轴或y轴的差.然后只有15个藏金点状压一下加dfs就行了. #include <iostream> #include <cstring> #include <cstdio> #include <cmath> #define inf 0X3f3f3f

hdu 4717 The Moving Points(三分)

题目链接:hdu 4717 The Moving Points 题意: 在二维平面上有n个点,每个点给出移动的方向和速度. 问在某个时刻,这些点中最大距离最小是多少,输出时刻和距离. 题解: 我们可以知道,每个点对的距离要么是单调递增,要么是有一个峰的函数. 举例画一下可知道合成的这个函数最多只有一个峰,所以可以用三分求解. 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;++i) 3 using namespa

三分算法

三分算法 二分算法解决的是具有单调性的问题. 三分算法解决的是抛物线的类型,上凸,下凹. mid=(Left+Right)/2; midmid=(Right+mid)/2; 题目类型有: HDU :3400  2298  4454  2438  3756 POJ:  3301   3737 ZOJ: 3203

uvalive 4986(三分查找)

题意:空间内有n个点,求一个最小体积的圆锥把所有点包进去.输出圆锥的高和底面半径.圆锥的底面圆心在(0,0),所有点的z坐标都大于等于0. 题解:因为圆锥体积是 V = 1/3 * π * r^2 * h ,这是一个二次函数,也就是个凸性函数,可以用三分查找的方式枚举两个高,然后找到对应的最小的r,比对两个高得到的体积继续三分查找. #include <cstdio> #include <cstring> #include <algorithm> #include &l

Lightoj 1088 - Points in Segments 【二分】

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1088 题意: 有一维的n个点和q条线段.询问每条线段上的点有多少个: 思路:寻找这些点中对于每条线段的上下界即可. 代码: #include <stdio.h> #include <ctime> #include <math.h> #include <limits.h> #include <complex> #include

Toxophily-数论以及二分三分

G - Toxophily Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 2298 Description The recreation center of WHU ACM Team has indoor billiards, Ping Pang, chess and bridge, toxophily, deluxe ballroom