E . Rain Gauge -UCF Local Programming Contest 2015
https://nanti.jisuanke.com/t/43390
题意
几何中心重合的 圆 和 正方形
给定正四边形边长 a 和 圆的半径 r,求重合面积
简单计算几何问题
思路
分块计算
注意精度和舍入问题
代码
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<bitset> #include<cassert> #include<cctype> #include<cmath> #include<cstdlib> #include<ctime> #include<deque> #include<iomanip> #include<list> #include<map> #include<queue> #include<set> #include<stack> #include<vector> #include <vector> #include <iterator> #include <utility> #include <sstream> #include <limits> #include <numeric> #include <functional> using namespace std; #define gc getchar() #define mem(a) memset(a,0,sizeof(a)) //#define sort(a,n,int) sort(a,a+n,less<int>()) #define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int,int> pii; typedef char ch; typedef double db; const double PI=acos(-1.0); const double eps=1e-6; const ll mod=1e9+7; const int inf=0x3f3f3f3f; const int maxn=1e5+10; const int maxm=100+10; bool compare(int a, int b) { return a < b;//升序 } double pi = 3.14159265358979; int main(){ double s = 0; double r = 0; int t = 0; cin >> t; while(t--) { cin >> s >> r; if(r > s*sqrt(2)/2) { //cout<<" !1 "; cout <<s*s <<endl; continue; } if(r < s/2) { //cout<<" !2 "; cout <<pi*r*r <<endl; continue; } double d = sqrt(r*r - s*s/4); double s1 = d*s*2; double a = acos(s/r/2); //cout<<a<<endl;//// double s2 = pi*r*r * (1-a/(2*pi)*8); cout <<fixed <<setprecision(2) <<s1 + s2 <<endl; } return 0; }