2021-09-15

E . Rain Gauge [ 问题 8629 ] [ 讨论 ]
Description
When going to your internship you got a nice apartment with a skylight. However, one crazy party later and you now have a square-shaped hole where your skylight used to be. Rather than telling the landlord, you decided you would “fix” it by putting a circular pot to collect the water but, as the saying goes, round peg square hole. You need to determine how much of the square the circle covers to help you determine if you should buy a larger pot. Don’t worry about the area not covered; you can do multiplication and subtraction easily in your head.
在这里插入图片描述

Given the radius of a circular pot and the length of the square skylight, calculate the amount of skylight rain area covered by the pot assuming the two shapes have the same center (i.e., are coaxial) with respect to the direction rain falls from (up). In other words, the center of the square will be directly above the center of the circle. See the picture for an example; let up be the direction from above the page, while the dotted square is the skylight and the solid circle is the pot to collect water.

Input
There is one input line, it contains a pair of integers, s,r (1≤s≤100, 1≤r≤100), which represents the length of the side of the skylight and the radius of the pot, respectively.

Output
Print a single decimal representing the area under the skylight that is covered by the pot. Round the answers to two decimal places (e.g., 1.234 rounds to 1.23 and 1.235 rounds to 1.24). For this problem, use 3.14159265358979 as the value of pi.

Samples
Input 复制
1 1
Output
1.00
Input 复制
8 5
Output
62.19
Input 复制
10 4
Output
50.27
Source
UCF 2021 Practice

分成三种情况
1 圆在正方形内
2 正方形在圆内
3 图示

#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979
int main()
{
	double s,r,A;
	cin>>s>>r;A=acos(s/(2*r));
	if(r*r>=s*s/2)
	printf("%.2lf",s*s); 
	else if(s/2>=r)
	printf("%.2lf",pi*r*r);
	else 
	{
		double s1,s2;
		//s1=2*s*sqrt(r*r-s*s/4);
		s1=2*r*r*sin(2*A);
		s2=r*r*(2*pi-8*A)/2;
		printf("%.2lf",s1+s2);
	}
 } 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值