24h購物| | PChome| 登入
2013-01-28 20:01:43| 人氣3,390| 回應0 | 上一篇 | 下一篇

[UVA] 10573 - Geometry Paradox

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

Problem G
Geometry Paradox

Time Limit: 1 Second

 

In the picture below you can see two small circles touching each other. The larger circle touches both pf them. The length of the common tangent inscribed inside the larger circle is t and the radiuses of the two smaller circles are r1 and r2. The centers of the three circles are collinear. You will be given the value of r1 and r2 or the value of t. You will have to find the area that is within the larger circle but out of the two smaller circles (marked gray in the picture). If the given data is not enough to find the gray area, print the line “Impossible.” in a single line

Input 

First line of the input file contains an integer N (N<=100) which denotes how many sets of inputs are there. Each of the next N lines contain a set of input.

 

Each set either contains one or two integer. If it contains one integer then it is the value of t, otherwise the two values are the values of r1 and r2.  All these integers are less than 100

 

Output 

For each line of input produce one line of output. This line contains the area of the gray part if the given information is enough to find the area of the gray part. Otherwise it contains the line “Impossible.” The area should have four digits after the decimal point. Assume that pi=2*cos-1(0).

 

Sample Input                           Output for Sample Input

2
10 10
15 20
628.3185
1884.9556

Problemsetter: Shahriar Manzoor, Member of Elite Problemsetters' Panel




其實這一題應該不算難,但是要判斷一行上有一個數字還是有兩個數字,
這一點對於初學者可能會比較難一點。
這裡提供一個簡潔的寫法,就是 po 這篇文的意義。

#include <stdio.h>
#include <math.h>
int main() {
    int t, a, b;
    const double pi = acos(-1);
    char cmd[50];
    scanf("%d", &t);
    gets(cmd);
    while(t--) {
        gets(cmd);
        if(sscanf(cmd, "%d %d", &a, &b) == 2) {
            printf("%.4lf\n", 2*a*b*pi);
        } else {
            sscanf(cmd, "%d", &a);
            printf("%.4lf\n", a*a*pi/8);
        }
    }
    return 0;
}

台長: Morris
人氣(3,390) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA][字串處理] 10115 - Automatic Editing
此分類上一篇:[UVA][二分搜+greedy] 907 - Winterim Backpacking Trip

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