题解:P16873 [GKS 2022 #B] Infinity Area

· · 题解

这个题特别简单我们只需要知道一个知识点即可做出此题:

圆的面积公式:S=\pi r^2。

因为 A<B 所以 R 最终会为 0,这点我们用 while 做即可,即直到 R=0,一直对 R 进行乘 A,之后算面积,除以 B,之后算面积即可。

保留六位小数我们可以用 print("%.6lf",x) 来实现。

代码如下:

#include<bits/stdc++.h>
using namespace std;
#define R read()
#define int long long
#define S r*r*M_PI//面积计算公式 M_PI就是圆周率
int R{
    int re=0,fg=1;
    char c;
    while (1){
        c=getchar();
        if (('0'<=c and c<='9') or c=='-')  break;
    }
    if (c=='-') c='0',fg=-1;
    while (1){
        re=re*10+c-'0';
        c=getchar();
        if (!(('0'<=c and c<='9') or c=='-'))   break;
    }
    return re*fg;
}
int T;
int r,a,b;
signed main(){
    T=R;
    for (int i=1;i<=T;i++){
        r=R,a=R,b=R;
        double ans=0;
        while (r){
            ans+=S;
            r*=a;
            ans+=S;
            r/=b;
        }
        printf("Case #%d: %.6lf\n",i,ans);
    }
}