ACdream1034:the cover circle

Problem Description

用半径相等的两个圆覆盖一个w*h的矩形,要求两圆不相交且必须在矩形内。求覆盖面积最大时两圆半径。

Input

输入包含多组数据,EOF结束。

每组数据包含一行,分别是两个实数w和h代表矩形的长和宽。

0<w,h<10000

Output

每组数据输出一行表示圆的半径,小数点后保留三位。

Sample Input

2.000 1.000

Sample Output

0.500

思路:我们可以以矩形的一个顶点为原点坐标(0,0),那么其斜对角的坐标为(w,h)

而这两个圆可以看做是从这两个点开始吹的气球

那么我们可以二分其半径

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define exp 1e-8

int main()
{
    double h,w,l,r,mid,x,y,mid2;
    while(~scanf("%lf%lf",&w,&h))
    {
        if(w<h)
            swap(w,h);
        l = 0,r = h/2;
        while(r-l>exp)
        {
            mid = (l+r)/2;//原点出发的圆的半径
            x = w-mid;//求出(w,h)出发的圆的圆心坐标
            y = h-mid;
            mid2 = sqrt((mid-x)*(mid-x)+(mid-y)*(mid-y))/2.0;//两圆心的距离除以2
            if(mid>mid2)
                r = mid;
            else
                l = mid;
        }
        printf("%.3f\n",l);
    }

    return 0;
}

ACdream1034:the cover circle

时间: 2024-10-07 11:12:44

ACdream1034:the cover circle的相关文章

acd the cover circle(分情况讨论)

Problem Description 用半径相等的两个圆覆盖一个w*h的矩形,要求两圆不相交且必须在矩形内.求覆盖面积最大时两圆半径. Input 输入包含多组数据,EOF结束. 每组数据包含一行,分别是两个实数w和h代表矩形的长和宽. 0<w,h<10000 Output 每组数据输出一行表示圆的半径,小数点后保留三位. Sample Input 2.000 1.000 Sample Output 0.500 (前提w>=h)当W>=2*h时,r=h/2; 当w<2*h时

poj 1266 Cover an Arc.

http://poj.org/problem?id=1266 Cover an Arc. Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 823   Accepted: 308 Description A huge dancing-hall was constructed for the Ural State University's 80-th anniversary celebration. The size of t

HUST 1017 - Exact cover (Dancing Links 模板题)

1017 - Exact cover 时间限制:15秒 内存限制:128兆 自定评测 5584 次提交 2975 次通过 题目描述 There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in exactly one of the selected rows. Try to find o

657. Judge Route Circle 判断线路成圆

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back to the original place. The move sequence is represented by a string. And each move is represent by a characte

SVG圆形&lt;circle&gt; 标签

1 <?xml version="1.0" standalone="no"?> 2 <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" 3 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> 4 5 <svg width="100%" height="100%" v

hzau 1208 Color Circle(dfs)

1208: Color Circle Time Limit: 1 Sec  Memory Limit: 1280 MBSubmit: 289  Solved: 85[Submit][Status][Web Board] Description There are colorful flowers in the parterre in front of the door of college and form many beautiful patterns. Now, you want to fi

java定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积

需求如下:(1)定义一个Circle类,包含一个double型的radius属性代表圆的半径,一个findArea()方法返回圆的面积. (2)定义一个类PassObject,在类中定义一个方法printAreas(),该方法的定义如下: public void printAreas(Cirlce c, int times) 在printAreas方法中打印输出1到time之间的每个整数半径值,以及对应的面积.例如,times为5,则输出半径1,2,3,4,5,以及对应的圆面积. 在main方法

搜索(DLX):HOJ 1017 - Exact cover

1017 - Exact cover Time Limit: 15s Memory Limit: 128MB Special Judge Submissions: 6751 Solved: 3519 Description There is an N*M matrix with only 0s and 1s, (1 <= N,M <= 1000). An exact cover is a selection of rows such that every column has a 1 in e

二分图匹配 + 最小点覆盖 - Vertex Cover

Vertex Cover Problem's Link Mean: 给你一个无向图,让你给图中的结点染色,使得:每条边的两个顶点至少有一个顶点被染色.求最少的染色顶点数. analyse: 裸的最小点覆盖问题,二分图的最大匹配,直接套模版即可. Time complexity: O(N^2) view code