2005 TCO Online Round 1 - RectangleError

RectangleError

Problem‘s Link

Problem Statement

You want to draw a rectangle on a piece of paper. Unfortunately, you are not a perfect draftsman. The lines you make, although straight, do not always have the correct lengths. The top edge has length in the inclusive range [topMin,topMax], the left edge in the inclusive range [leftMin,leftMax], and the right edge in the inclusive range [rightMin,rightMax]. Fortunately, the left, top and right edges are at right angles to each other and meet (where applicable) at their ends. The bottom edge is made by connecting the bottom end of the left edge to the bottom end of the right edge. Return the maximum length the bottom edge could be minus the minimum length the bottom edge could be.

Definition

-Class: RectangleError

-Method: bottomRange

-Parameters: double, double, double, double, double, double

-Returns: double

-Method signature: double bottomRange(double topMin, double topMax, double leftMin, double leftMax, double rightMin, double rightMax)

-(be sure your method is public)

Notes

- Your return value must have an absolute or relative error less than 1e-9.

Constraints

- Each input will be between 5 and 100 inclusive.

- topMin will not be greater than topMax.

- leftMin will not be greater than leftMax.

- rightMin will not be greater than rightMax.

----------------------------------------------------------------------------

Mean:

给定一个矩形的顶边、左边、右边的长度范围,求连接左边和右边下顶点的斜边长的最大可能长度与最小可能长度的差.

analyse:

Time complexity: O(1)

view code

#include <bits/stdc++.h>
using namespace std;

class RectangleError
{
public:
   double bottomRange(double topMin, double topMax, double leftMin, double leftMax, double rightMin, double rightMax)
   {

double Max = max(hypot(topMax, leftMin-rightMax) , hypot(topMax, leftMax-rightMin));

double y;
       if(rightMin >= leftMax)
           y = rightMin - leftMax;
       else if(leftMin >= rightMax)
           y = rightMax - leftMin;
       else
           y = 0;

double Min = hypot(topMin, y);
       return Max-Min;
   }
};

int main()
{
    double topMin,topMax,leftMin, leftMax, rightMin,rightMax;
    while(cin>>topMin>>topMax>>leftMin>>leftMax>>rightMin>>rightMax)
    {
        RectangleError rectangleError;
        double ans=rectangleError.bottomRange(topMin,topMax,leftMin,leftMax,rightMin,rightMax);
        printf("%f\n",ans);
    }
    return 0;
}
/*

*/

时间: 2024-10-22 12:56:28

2005 TCO Online Round 1 - RectangleError的相关文章

TCO 2014 Round 1C 概率DP

TCO round 1C的 250 和500 的题目都太脑残了,不说了. TCO round 1C 950 一个棋子,每次等概率的向左向右移动,然后走n步之后,期望cover的区域大小?求cover,肯定就是dp[l][r][n], 走了n步之后,左边cover了l,右边cover了r. 一开始DP没有搞清楚,这个要画一下图就更清楚了. 转移方程就是概率的传递方向. 1: double dp[505][505][2]; // l,r,n steps unsed; 2: class RedPain

TCO 2015 Round 1B DIV1 500 概率题

[题意]现在有一些线索,每个线索被发现的概率p[i],如果线索i被知道,那么其他线索也可能会被知道,用vector<string> c给出,c[i][j]='Y'表示知道i这个线索,j这个线索能直接知道,问最终发现的线索个数的期望. 所有p[i]的和不是1... 求每个clue被选中的概率,由题意,如果知道第i个数,那么可以立即知道其他一些点,那么可以先用floyd,求出当知道结点i后应该知道哪些结点. 然后两重求反,1-(1-p[i1])(1-p[i2])...(1-p[ik])就是所求答案

TCO 2015 Round 2A DIV1

ModModMod 傻逼数论 题意: 这是一道卖萌的题..给你一个取模序列$m$,令$f(x)=(\cdots (x\ mod\ m[0])\ mod m[1])\mod m[2]\cdots $,问你$\sum_{i=1}^R f(i)$的值是多少 题解: 容易知道一点,若$i<j$且$m[i]\le m[j]$,那么$m[j]$就是没有意义的,所以首先将m变成递减序列.接下来观察每次取模后的结果,由于是从1到R,所以序列第一次取模后会变成: $$(0+1+2+\cdots+m[0]-1)+(

2018 TCO Algorithm Round 1B

250 LineOff 随便搞 1 #include <bits/stdc++.h> 2 using namespace std; 3 4 class LineOff { 5 public: 6 int movesToDo(string points) { 7 stack<char> st; 8 int ret = 0, l = points.length(); 9 for(int i = 0; i < l; ++i){ 10 if(!st.empty() &&

网络流专栏

最大流 POJ 1273 Drainage Ditches POJ 1274 The Perfect Stall (二分图匹配) POJ 1698 Alice's Chance(构图) POJ 1459 Power Network(构图) POJ 2112 Optimal Milking (二分) POJ 2455 Secret Milking Machine (二分) POJ 3189 Steady Cow Assignment (枚举) POJ 1637 Sightseeing tour (

网络流柱

最大流量 POJ 1273 Drainage Ditches POJ 1274 The Perfect Stall (二分图匹配) POJ 1698 Alice's Chance(构图) POJ 1459 Power Network(构图) POJ 2112 Optimal Milking (二分) POJ 2455 Secret Milking Machine (二分) POJ 3189 Steady Cow Assignment (枚举) POJ 1637 Sightseeing tour

网络流题集

最大流POJ 1273 Drainage DitchesPOJ 1274 The Perfect Stall (二分图匹配)POJ 1698 Alice's Chance(构图)POJ 1459 Power Network(构图)POJ 2112 Optimal Milking (二分)POJ 2455 Secret Milking Machine (二分)POJ 3189 Steady Cow Assignment (枚举)POJ 1637 Sightseeing tour (混合图欧拉回路)

TCO14 2C L2: CliqueGraph,graph theory, clique

称号:http://community.topcoder.com/stat?c=problem_statement&pm=13251&rd=16017 參考:http://apps.topcoder.com/wiki/display/tc/TCO+2014+Round+2C 假设用先计算出每条边,用邻接矩阵来表示图,然后用BFS或 Floyd-Warshall算法来计算距离的话.时间复杂度是O(N^3),会超时.依据题名的提示知要利用clique graph的性质来做.基本思想是在BFS的

动态规划 Dynamic Programming

March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处. 前言 本文翻译自TopCoder上的一篇文章: Dynamic Programming: From novice to advanced ,并非严格逐字逐句翻译,其中加入了自己的