24h購物| | PChome| 登入
2013-07-05 16:00:02| 人氣840| 回應0 | 上一篇 | 下一篇

[UVA][math] 10466 - How Far?

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

Return of the Aztecs

Problem D: How Far?

Time Limit: 4 seconds
Memory Limit: 32 MB

As you probably know, the earth moves round the sun, and the moon moves round the earth. Both the earth and the moon follow elliptical paths. But for this problem, we will consider their paths to be circular. So the earth moves round the sun in a circular path with the sun in the center, and likewise the moon moves round the earth in a circular path with the earth in the center. This same kind of planetary system can be observed elsewhere in the galaxy. So, for a general case, let there are n such bodies b1, b2, b3, ... bn, where b1 moves round the sun, which is stationary, from a distance of r1. Body b2 moves round b1 from a distance of r2, and so on. Body bi completes a cycle in nonzero-time ti.

Given the r�s and the t�s, you have to find out the distances d�s of the bodies from the sun at a given time T. At T = 0, all the bodies lie in their farthest positions from the sun.

Input

Input consists of multiple test cases. Each case starts with n and T in a line. The following n lines each contains first ri and then ti for i = 1, 2, ... n. Input is terminated by EOF. All the inputs are positive integers. There won�t be more than 50 bodies in a single solar system.

Output

For each case, there should a new line. Print all the d�s in that line separated by spaces. Each d should have 4-digits after the decimal point.

Sample Input

3 5
20 5
30 5
40 5

Sample Output

20.0000 50.0000 90.0000

[ The image is from http://www.earthsky.com ]

Problem setter: Sadrul Habib Chowdhury (Adil)
Solution author: Monirul Hasan (Tomal)

Man has his will, - but woman has her way.
-- Oliver Wendell Holmes


題目是講很多星球, 誰繞太陽, 誰繞誰, 誰繞誰 ... 分別有公轉週期與公轉半徑。
將太陽座標化(0, 0) 然後對於每個點進行公轉周期的計算。

#include <stdio.h>
#include <math.h>

int main() {
    int n, i;
    double T;
    const double pi = acos(-1);
    while(scanf("%d %lf", &n, &T) == 2) {
        double theta = 0, r, t;
        double x = 0, y = 0;
        for(i = 0; i < n; i++) {
            scanf("%lf %lf", &r, &t);
            theta = 2*pi*T/t;
            x += r*sin(theta);
            y += r*cos(theta);
            if(i)   putchar(' ');
            printf("%.4lf", hypot(x, y));
        }
        puts("");
    }
    return 0;
}

台長: Morris
人氣(840) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 10406 - Cutting tabletops
此分類上一篇:[UVA] 10410 - Tree Reconstruction

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