S5來襲4/11旗艦上市工程師靠存股年領百萬股息攝影界美人正妹指定相機款晚會結束續攤大腸花 學...
2013-06-29 22:21:02 人氣(151) | 回應(0) | 推薦(0) | 收藏(0) 上一篇 | 下一篇

[UVA] 11834 - Elevator

0
收藏
0
推薦


  Elevator 

The FCC (Factory of Cylinders of Carbon) manufactures various types of cylinders of carbon. FCC is installed on the tenth floor of a building, and uses the several building's elevators to transport the cylinders. For security, the cylinders must be transported in the upright position, and since they are heavy, at most two cylinders can be transported in a single elevator ride. The elevators have the shape of a parallelepiped and their height is always greater than the height of the cylinders.

To minimize the number of elevator trips to transport the cylinders, the FCC wants, whenever possible, to put two cylinders in the elevator. The figure below illustrates, schematically (top view) a case where this is possible (a), and a case where this is not possible (b):

epsfbox{p11834.eps}

As there is a very large amount of elevators and types of cylinders, FCC hired you to write a program that, given the dimensions of the elevator and of the two cylinders, determines whether it is possible to put the two cylinders in the elevator.

Input 

The input contains several test cases. The first and only line of each test case contains four integers L, C, R1 and R2 , separated by blanks, indicating the width ( 1$ le$L$ le$100) and the length ( 1$ le$C$ le$100) of the elevator and the radii of the cylinders ( 1$ le$R1, R2$ le$100).

The last test case is followed by a line containing four zeros separated by blanks.

Output 

For each test case your program should print a single line with a single character, `S' if you can put the two cylinders in the elevator and `N' otherwise.

Sample Input 

11 9 2 3
7 8 3 2
10 15 3 7
8 9 3 2
0 0 0 0

Sample Output 

S
N
N
S



題目解法:
基本上思考一下, 要讓這兩個圓塞進矩形中, 不一定是要公切於邊。
但有個原則一定可行, 兩個圓剛好放在兩個對角的角落,
如果這兩個圓還是外離, 便一定可行, 因此將圖形座標化就可以解了。


#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int main() {
    double L, C, R1, R2;
    while(scanf("%lf %lf %lf %lf", &L ,&C, &R1, &R2) == 4) {
        if(L+C+R1+R2 == 0)  break;
        // (x-R1)^2 + (y-R1)^2 = R1^R1
        // (x-(L-R2))^2 + (y-(C-R2))^2 = R2^R2
        double x1, x2, y1, y2;
        x1 = R1, y1 = R1;
        x2 = L-R2, y2 = C-R2;
        double a = R1, b = R2, c = sqrt(pow(x1-x2,2)+pow(y1-y2,2));
        if(a+b <= c + 1e-6 && R1+R1 <= L && R1+R1 <= C && R2+R2 <= L && R2+R2 <= C)
            puts("S");
        else
            puts("N");
    }
    return 0;
}

11834Elevator
台長:Morris
人氣(151) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11835 - Formula 1
此分類上一篇:[UVA] 11718 - Fantasy of a Summation

我要回應
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入以下數字 (ex:123)

(有*為必填)
詳全文