24h購物| | PChome| 登入
2013-07-10 07:30:50| 人氣918| 回應0 | 上一篇 | 下一篇

[UVA] 11326 - Laser Pointer

推薦 0 收藏 0 轉貼0 訂閱站台

Problem D: Laser Pointer

Jake and his friends have been walking around a house of mirrors at a carnival for quite some time now. While Jake's friends are still interested in seeing a few rooms, Jake is quite bored. He decides to wait by the exit while the rest of them search the remainder of the house. Jake also has a laser pointer which he plays with to help pass the time.

The exit is located at the end of a hallway of length L and width W where 0 < L,W ≤ 10,000. The walls along the length of the hallway are lined with mirrors. Jake is at the start of the hallway and is leaning against the right wall. He shines his laser pointer toward the exit making an angle (in degrees) of 0 ≤ θ < 90 with the right wall.

The laser beam travels some distance A, perhaps reflecting off one or more walls, until it illuminates a spot at the end of the hall on the exit door. In his boredom, Jake wonders how much further this beam travelled than if he had shone the laser pointer directly at the spot on the door. That is, if the Euclidean distance from the laser pointer to the illuminated point on the wall is B, Jake is trying to determine the ratio A/B.

The first line of input indicates how many test cases follow. Each test case consists of three integers L, W, and θ on one line.

The output for each test case is a single line containing the value A/B rounded to three decimal places.

Sample input

2
10 5 45
12 12 75

Output for sample input

1.414
3.732

Zachary Friggstad

將圖形補滿擴充,反彈的題目都是這麼去解的。
但要考慮反彈上下面得奇偶數的數量,才能去決定離地面的高度到底是 x 還是 w-x。

#include <stdio.h>
#include <math.h>
using namespace std;
int main() {
    int testcase;
    double pi = acos(-1);
    double L, W, theta;
    scanf("%d", &testcase);
    while(testcase--) {
        scanf("%lf %lf %lf", &L, &W, &theta);
        theta = theta/180*pi;
        double A, B;
        A = L/cos(theta);
        B = A*sin(theta);
        int cross = (int)(B/W);
        B = fmod(B, W);
        if(cross&1)
            B = W-B;
        B = sqrt(B*B+L*L);
        printf("%.3lf\n", A/B);
    }
    return 0;
}

台長: Morris
人氣(918) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 11348 - Exhibition
此分類上一篇:[UVA][最短路] 11377 - Airport Setup

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文