UCF Local Programming Contest 2013(Practice)I.Ty G. Too?

14 篇文章 0 订阅
10 篇文章 0 订阅

UCF Local Programming Contest 2013(Practice)I.Ty G. Too?

The Chinese Taijitu symbol, also known as the Yin and Yang, symbolizes the duality and balance of everything. It appears in many contexts, including ancient Confucian writings, martial arts, and even the national flag of South Korea. The Taijitu is always shown with the yin (dark side) and the yang (light side) in balance. But, what happens when they are unbalanced?

The typical Taijitu has the dark (yin) and light (yang) side separated by a specific curve that is related to the apparent path of the sun around the earth (the ecliptic), but for the purposes of this problem, we’ll simply use two connected semicircles as shown below. In the image on the left, the Taijitu is balanced, with an equal area of yin and yang. The image on the right has significantly more yang (because the upper semicircle has a larger radius than the lower semicircle), and is therefore unbalanced.

Note: Each side is usually depicted with a “seed” (a small dot) of the opposite color. For simplicity, we will ignore this.

The Problem:

Given the overall radius (in centimeters) of the Taijitu, and the radius (in centimeters) of the upper semicircle (as shown in the images above), determine the total area of yin and yang in the corresponding Taijitu. Note that the yang (the light side) always appears on the left side of the Taijitu, and the two semicircles defining the division are always oriented as shown above.

Use value of 3.14159 for π .

The Input:

There will be multiple Taijitu(s). Input begins with an integer, n(1≤n≤50), on a line by itself, indicating the number of Taijitu(s) to examine. On each of the next nn input lines will be two integers, a and b(1≤b≤a≤100), where a represents the overall radius of the Taijitu, and bb represents the radius of the upper semicircle.

The Output:

For each Taijitu in the input, print line of the form “Taijitu #t: yin x, yang y”, where tt is the Taijitu number (starting from 1), x is the area of the yin (the dark side) in square centimeters, and y is the area of the yang (the light side) in square centimeters. Round the area to the nearest two decimal places (examples: 1.274 would round to 1.27 and 1.275 would round to 1.28). Leave a blank line after the output for each data set. Follow the format illustrated in Sample Output.

样例输入

2
10 5
12 7

样例输出

Taijitu #1: yin 157.08, yang 157.08

Taijitu #2: yin 188.50, yang 263.89

这道题考了一个四舍五入,还是挺坑的,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pi 3.14159
int main(){
    int t;
    cin>>t;
    for(int i=1;i<=t;i++){
        double r,r1,r2;
        cin>>r>>r1;r2=r-r1;
        double s=(pi*(r)*(r)-pi*r1*r1-pi*r2*r2)/2;
        printf("Taijitu #%d: yin %.2f, yang %.2f\n",i,(int)(((s+pi*r2*r2)+0.00501)*100)/100.0,(int)(((s+pi*r1*r1)+0.00501)*100)/100.0);
        puts("");
    }
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旺 崽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值