24h購物| | PChome| 登入
2012-06-23 09:10:58| 人氣937| 回應1 | 上一篇 | 下一篇

[UVA][幾何] 837 - Light and Transparencies

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


  Light and Transparencies 

When light traverses a transparent film, some energy is absorbed and the rest is transmitted to other side of the film. The percentage of light that is transmitted may be defined as Transparency Coefficient.

When several films are in the same direction of light, the correspondent transparency coefficients are multiplied. The goal of this problem is to determine the percentage of light that is projected on the ground, after traversing a given set of films.

epsfbox{p837.eps}

Figure 1 Three films and correspondent Transparent Coeficients.


Consider the set of lines segments in fig. 1. They represent transparent films in the above conditions (transparency coefficients are written in brackets). Also consider that light is propagating in the vertical direction, from top to bottom.

Accordingly to the figure, the end points of the lines define a set of projected segments onto the ground (ground is represented by the X axe). For each projected segment, it is possible to evaluate the percentage of light that reaches the ground and, for the entire set of segments, a list can be obtained:

-inf, 2.0 -> 1.000
2.0, 4.0 -> 0.900
4.0, 7.0 -> 0.630
7.0, 9.0 -> 0.504
9.0, 13.5 -> 0.560
13.0, 17.0 -> 0.800
17.0, +inf -> 1.000

To simplify the problem, it is assumed that neither vertical lines nor crossing lines are given. Also no coincidences exist in the vertical projection of all given points (in other words, the X coordinates of the end points are all different from each other). On the other hand, a coordinate may be any real value from - $ infty$ to + $ infty$.

Input 

The input begins with a single positive integer on a line by itself indicating the number of the cases following, each of them as described below. This line is followed by a blank line, and there is also a blank line between two consecutive inputs.


The input is a text file containing several lines, as follows.

The first line of the input contains the number NL (integer format) of line segments. It is followed by NL lines of text defining, each one, a line segment.

Accordingly to the above explanations, a line segment is defined by the coordinates of its two end points P1 and P2 and the transparency coefficient r, in the sequence xyxyr, separated by single spaces (all the five values are in the real format). No order is considered for the two points P1 and P2.

Output 

For each test case, the output must follow the description below. The outputs of two consecutive cases will be separated by a blank line.


The first line of the output contains the number NP (integer format) of projected segments. It is followed by NP lines of text, defining, each one, a projected segment. These lines must be sorted in ascending order of X values.

A projected segment must be defined by its coordinates X1 and X2, followed by the evaluated percentage of light. All the tree values must be in real format, rounded to 3 decimal digits and separated by single spaces. Infinite values must be represented by `-inf' or `+inf'.

Sample Input 

1

3
2.0 2.0 9.0 2.0 0.9
13.5 2.0 4.0 8.5 0.7
17.0 10.0 7.0 8.5 0.8

Sample Output 

7
-inf 2.000 1.000
2.000 4.000 0.900
4.000 7.000 0.630
7.000 9.000 0.504
9.000 13.500 0.560
13.500 17.000 0.800
17.000 +inf 1.000



A. Augusto Sousa, ACM-UP'2001

做法 : 其實不用管 y 的值, 然後將出現的 x 座標全部記錄, 挑出所有不同的 x 座標值
之後, 就用 O(n) 去做計算

#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    int t, nl;
    scanf("%d", &t);
    while(t--) {
        scanf("%d", &nl);
        double l[100], r[100], n[100], y;
        double x[200];
        int i, j, idx = 0;
        for(i = 0; i < nl; i++) {
            scanf("%lf %lf %lf %lf %lf", l+i, &y, r+i, &y, n+i);
            x[idx++] = l[i], x[idx++] = r[i];
        }
        sort(x, x+idx);
        int didx = 0;
        double diff[200] = {x[0]};
        for(i = 1; i < idx; i++) {
            if(x[i] != diff[didx]) {
                diff[++didx] = x[i];
            }
        }
        printf("%d\n", didx+2);
        printf("-inf %.3lf 1.000\n", diff[0]);
        for(i = 0; i < didx; i++) {
            double m = (diff[i]+diff[i+1])/2, nn = 1;
            for(j = 0; j < nl; j++) {
                if((l[j] <= m && m <= r[j]) ||
                    (l[j] >= m && m >= r[j]))
                        nn *= n[j];
            }
            printf("%.3lf %.3lf %.3lf\n", diff[i], diff[i+1], nn);
        }
        printf("%.3lf +inf 1.000\n", diff[didx]);
        if(t)
            puts("");
    }
    return 0;
}

台長: Morris
人氣(937) | 回應(1)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][幾何] 10263 - Railway
此分類上一篇:[UVA] 12416 - Excessive Space Remover

xem phim online
nice article...
2017-10-03 14:13:33
是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文