跳到正文

题解

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

__YiChaQAQ__o_O约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年6月11日
收录
2026年6月12日
更新
2026年11月15日
篇幅
约 2 分钟
获赞
2
题目
P16873

版本

  1. v1当前

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

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

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

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

代码如下:

C++
#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);
	}
}
原文
存档评论1 条抓取于